appwrite-utils-cli 1.9.7 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CONFIG_TODO.md +1189 -1189
- package/README.md +1004 -1004
- package/SELECTION_DIALOGS.md +145 -145
- package/SERVICE_IMPLEMENTATION_REPORT.md +462 -462
- package/package.json +6 -3
- package/scripts/copy-templates.ts +23 -23
- package/src/adapters/index.ts +11 -37
- package/src/backups/operations/bucketBackup.ts +277 -277
- package/src/backups/operations/collectionBackup.ts +310 -310
- package/src/backups/operations/comprehensiveBackup.ts +342 -342
- package/src/backups/schemas/bucketManifest.ts +78 -78
- package/src/backups/schemas/comprehensiveManifest.ts +76 -76
- package/src/backups/tracking/centralizedTracking.ts +352 -352
- package/src/cli/commands/configCommands.ts +265 -201
- package/src/cli/commands/databaseCommands.ts +931 -879
- package/src/cli/commands/functionCommands.ts +333 -332
- package/src/cli/commands/importFileCommands.ts +815 -0
- package/src/cli/commands/schemaCommands.ts +141 -141
- package/src/cli/commands/storageCommands.ts +2 -3
- package/src/cli/commands/transferCommands.ts +454 -457
- package/src/collections/attributes.ts.backup +1555 -1555
- package/src/collections/{attributes.ts → columns.ts} +15 -10
- package/src/collections/indexes.ts +350 -352
- package/src/collections/methods.ts +714 -700
- package/src/collections/tableOperations.ts +29 -8
- package/src/collections/transferOperations.ts +376 -377
- package/src/collections/wipeOperations.ts +449 -346
- package/src/databases/methods.ts +49 -49
- package/src/databases/setup.ts +77 -77
- package/src/examples/yamlTerminologyExample.ts +346 -346
- package/src/functions/deployments.ts +221 -220
- package/src/functions/fnConfigDiscovery.ts +2 -2
- package/src/functions/methods.ts +284 -284
- package/src/functions/templates/count-docs-in-collection/README.md +53 -53
- package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -159
- package/src/functions/templates/count-docs-in-collection/src/request.ts +8 -8
- package/src/functions/templates/hono-typescript/README.md +285 -285
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +73 -73
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +105 -105
- package/src/functions/templates/hono-typescript/src/app.ts +179 -179
- package/src/functions/templates/hono-typescript/src/context.ts +102 -102
- package/src/functions/templates/hono-typescript/src/{index.ts → main.ts} +53 -53
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +118 -118
- package/src/functions/templates/typescript-node/README.md +31 -31
- package/src/functions/templates/typescript-node/src/context.ts +102 -102
- package/src/functions/templates/typescript-node/src/{index.ts → main.ts} +29 -29
- package/src/functions/templates/uv/README.md +30 -30
- package/src/functions/templates/uv/pyproject.toml +29 -29
- package/src/functions/templates/uv/src/context.py +124 -124
- package/src/functions/templates/uv/src/{index.py → main.py} +45 -45
- package/src/init.ts +62 -62
- package/src/interactiveCLI.ts +1095 -1030
- package/src/main.ts +1517 -1670
- package/src/migrations/afterImportActions.ts +579 -580
- package/src/migrations/appwriteToX.ts +634 -630
- package/src/migrations/comprehensiveTransfer.ts +2149 -2149
- package/src/migrations/dataLoader.ts +1729 -1702
- package/src/migrations/importController.ts +440 -428
- package/src/migrations/importDataActions.ts +315 -315
- package/src/migrations/relationships.ts +333 -334
- package/src/migrations/services/DataTransformationService.ts +195 -195
- package/src/migrations/services/FileHandlerService.ts +310 -310
- package/src/migrations/services/ImportOrchestrator.ts +674 -665
- package/src/migrations/services/RateLimitManager.ts +362 -362
- package/src/migrations/services/RelationshipResolver.ts +460 -460
- package/src/migrations/services/UserMappingService.ts +344 -344
- package/src/migrations/services/ValidationService.ts +333 -333
- package/src/migrations/transfer.ts +987 -942
- package/src/migrations/yaml/YamlImportConfigLoader.ts +438 -438
- package/src/migrations/yaml/YamlImportIntegration.ts +438 -438
- package/src/migrations/yaml/generateImportSchemas.ts +1347 -1347
- package/src/schemas/authUser.ts +23 -23
- package/src/setup.ts +8 -8
- package/src/setupCommands.ts +5 -6
- package/src/setupController.ts +42 -42
- package/src/shared/backupMetadataSchema.ts +93 -93
- package/src/shared/backupTracking.ts +211 -211
- package/src/shared/confirmationDialogs.ts +326 -326
- package/src/shared/migrationHelpers.ts +232 -232
- package/src/shared/operationLogger.ts +20 -20
- package/src/shared/operationQueue.ts +326 -327
- package/src/shared/operationsTable.ts +338 -338
- package/src/shared/operationsTableSchema.ts +60 -60
- package/src/shared/progressManager.ts +277 -277
- package/src/shared/relationshipExtractor.ts +214 -214
- package/src/shared/selectionDialogs.ts +775 -722
- package/src/storage/backupCompression.ts +88 -88
- package/src/storage/methods.ts +695 -682
- package/src/storage/schemas.ts +205 -205
- package/src/tables/indexManager.ts +408 -408
- package/src/types/node-appwrite-tablesdb.d.ts +43 -43
- package/src/types.ts +9 -9
- package/src/users/methods.ts +358 -359
- package/src/utils/configMigration.ts +347 -347
- package/src/utils/index.ts +2 -2
- package/src/utils/loadConfigs.ts +457 -449
- package/src/utils/setupFiles.ts +1236 -1238
- package/src/utilsController.ts +1263 -1213
- package/tests/README.md +496 -496
- package/tests/adapters/AdapterFactory.test.ts +276 -276
- package/tests/integration/syncOperations.test.ts +462 -462
- package/tests/jest.config.js +24 -24
- package/tests/migration/configMigration.test.ts +545 -545
- package/tests/setup.ts +61 -61
- package/tests/testUtils.ts +339 -339
- package/tests/utils/loadConfigs.test.ts +349 -349
- package/tests/validation/configValidation.test.ts +411 -411
- package/tsconfig.json +44 -44
- package/.appwrite/.yaml_schemas/appwrite-config.schema.json +0 -380
- package/.appwrite/.yaml_schemas/collection.schema.json +0 -255
- package/.appwrite/collections/Categories.yaml +0 -182
- package/.appwrite/collections/ExampleCollection.yaml +0 -36
- package/.appwrite/collections/Posts.yaml +0 -227
- package/.appwrite/collections/Users.yaml +0 -149
- package/.appwrite/config.yaml +0 -109
- package/.appwrite/import/README.md +0 -148
- package/.appwrite/import/categories-import.yaml +0 -129
- package/.appwrite/import/posts-import.yaml +0 -208
- package/.appwrite/import/users-import.yaml +0 -130
- package/.appwrite/importData/categories.json +0 -194
- package/.appwrite/importData/posts.json +0 -270
- package/.appwrite/importData/users.json +0 -220
- package/.appwrite/schemas/categories.json +0 -128
- package/.appwrite/schemas/exampleCollection.json +0 -52
- package/.appwrite/schemas/posts.json +0 -173
- package/.appwrite/schemas/users.json +0 -125
- package/dist/adapters/AdapterFactory.d.ts +0 -94
- package/dist/adapters/AdapterFactory.js +0 -420
- package/dist/adapters/DatabaseAdapter.d.ts +0 -243
- package/dist/adapters/DatabaseAdapter.js +0 -50
- package/dist/adapters/LegacyAdapter.d.ts +0 -50
- package/dist/adapters/LegacyAdapter.js +0 -615
- package/dist/adapters/TablesDBAdapter.d.ts +0 -45
- package/dist/adapters/TablesDBAdapter.js +0 -611
- package/dist/adapters/index.d.ts +0 -11
- package/dist/adapters/index.js +0 -12
- package/dist/backups/operations/bucketBackup.d.ts +0 -19
- package/dist/backups/operations/bucketBackup.js +0 -197
- package/dist/backups/operations/collectionBackup.d.ts +0 -30
- package/dist/backups/operations/collectionBackup.js +0 -201
- package/dist/backups/operations/comprehensiveBackup.d.ts +0 -25
- package/dist/backups/operations/comprehensiveBackup.js +0 -238
- package/dist/backups/schemas/bucketManifest.d.ts +0 -93
- package/dist/backups/schemas/bucketManifest.js +0 -33
- package/dist/backups/schemas/comprehensiveManifest.d.ts +0 -108
- package/dist/backups/schemas/comprehensiveManifest.js +0 -32
- package/dist/backups/tracking/centralizedTracking.d.ts +0 -34
- package/dist/backups/tracking/centralizedTracking.js +0 -274
- package/dist/cli/commands/configCommands.d.ts +0 -8
- package/dist/cli/commands/configCommands.js +0 -166
- package/dist/cli/commands/databaseCommands.d.ts +0 -14
- package/dist/cli/commands/databaseCommands.js +0 -644
- package/dist/cli/commands/functionCommands.d.ts +0 -7
- package/dist/cli/commands/functionCommands.js +0 -330
- package/dist/cli/commands/schemaCommands.d.ts +0 -7
- package/dist/cli/commands/schemaCommands.js +0 -169
- package/dist/cli/commands/storageCommands.d.ts +0 -5
- package/dist/cli/commands/storageCommands.js +0 -143
- package/dist/cli/commands/transferCommands.d.ts +0 -5
- package/dist/cli/commands/transferCommands.js +0 -384
- package/dist/collections/attributes.d.ts +0 -13
- package/dist/collections/attributes.js +0 -1333
- package/dist/collections/indexes.d.ts +0 -12
- package/dist/collections/indexes.js +0 -217
- package/dist/collections/methods.d.ts +0 -19
- package/dist/collections/methods.js +0 -587
- package/dist/collections/tableOperations.d.ts +0 -86
- package/dist/collections/tableOperations.js +0 -447
- package/dist/collections/transferOperations.d.ts +0 -8
- package/dist/collections/transferOperations.js +0 -412
- package/dist/collections/wipeOperations.d.ts +0 -16
- package/dist/collections/wipeOperations.js +0 -233
- package/dist/config/ConfigManager.d.ts +0 -450
- package/dist/config/ConfigManager.js +0 -650
- package/dist/config/configMigration.d.ts +0 -87
- package/dist/config/configMigration.js +0 -390
- package/dist/config/configValidation.d.ts +0 -66
- package/dist/config/configValidation.js +0 -358
- package/dist/config/index.d.ts +0 -8
- package/dist/config/index.js +0 -7
- package/dist/config/services/ConfigDiscoveryService.d.ts +0 -122
- package/dist/config/services/ConfigDiscoveryService.js +0 -322
- package/dist/config/services/ConfigLoaderService.d.ts +0 -129
- package/dist/config/services/ConfigLoaderService.js +0 -535
- package/dist/config/services/ConfigMergeService.d.ts +0 -208
- package/dist/config/services/ConfigMergeService.js +0 -308
- package/dist/config/services/ConfigValidationService.d.ts +0 -214
- package/dist/config/services/ConfigValidationService.js +0 -310
- package/dist/config/services/SessionAuthService.d.ts +0 -225
- package/dist/config/services/SessionAuthService.js +0 -456
- package/dist/config/services/__tests__/ConfigMergeService.test.d.ts +0 -1
- package/dist/config/services/__tests__/ConfigMergeService.test.js +0 -271
- package/dist/config/services/index.d.ts +0 -13
- package/dist/config/services/index.js +0 -10
- package/dist/config/yamlConfig.d.ts +0 -722
- package/dist/config/yamlConfig.js +0 -702
- package/dist/databases/methods.d.ts +0 -6
- package/dist/databases/methods.js +0 -35
- package/dist/databases/setup.d.ts +0 -5
- package/dist/databases/setup.js +0 -45
- package/dist/examples/yamlTerminologyExample.d.ts +0 -42
- package/dist/examples/yamlTerminologyExample.js +0 -272
- package/dist/functions/deployments.d.ts +0 -4
- package/dist/functions/deployments.js +0 -146
- package/dist/functions/fnConfigDiscovery.d.ts +0 -3
- package/dist/functions/fnConfigDiscovery.js +0 -108
- package/dist/functions/methods.d.ts +0 -16
- package/dist/functions/methods.js +0 -174
- package/dist/functions/pathResolution.d.ts +0 -37
- package/dist/functions/pathResolution.js +0 -185
- package/dist/functions/templates/count-docs-in-collection/README.md +0 -54
- package/dist/functions/templates/count-docs-in-collection/package.json +0 -25
- package/dist/functions/templates/count-docs-in-collection/src/main.ts +0 -159
- package/dist/functions/templates/count-docs-in-collection/src/request.ts +0 -9
- package/dist/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
- package/dist/functions/templates/hono-typescript/README.md +0 -286
- package/dist/functions/templates/hono-typescript/package.json +0 -26
- package/dist/functions/templates/hono-typescript/src/adapters/request.ts +0 -74
- package/dist/functions/templates/hono-typescript/src/adapters/response.ts +0 -106
- package/dist/functions/templates/hono-typescript/src/app.ts +0 -180
- package/dist/functions/templates/hono-typescript/src/context.ts +0 -103
- package/dist/functions/templates/hono-typescript/src/index.ts +0 -54
- package/dist/functions/templates/hono-typescript/src/middleware/appwrite.ts +0 -119
- package/dist/functions/templates/hono-typescript/tsconfig.json +0 -20
- package/dist/functions/templates/typescript-node/README.md +0 -32
- package/dist/functions/templates/typescript-node/package.json +0 -25
- package/dist/functions/templates/typescript-node/src/context.ts +0 -103
- package/dist/functions/templates/typescript-node/src/index.ts +0 -29
- package/dist/functions/templates/typescript-node/tsconfig.json +0 -28
- package/dist/functions/templates/uv/README.md +0 -31
- package/dist/functions/templates/uv/pyproject.toml +0 -30
- package/dist/functions/templates/uv/src/__init__.py +0 -0
- package/dist/functions/templates/uv/src/context.py +0 -125
- package/dist/functions/templates/uv/src/index.py +0 -46
- package/dist/init.d.ts +0 -2
- package/dist/init.js +0 -57
- package/dist/interactiveCLI.d.ts +0 -31
- package/dist/interactiveCLI.js +0 -898
- package/dist/main.d.ts +0 -2
- package/dist/main.js +0 -1180
- package/dist/migrations/afterImportActions.d.ts +0 -17
- package/dist/migrations/afterImportActions.js +0 -306
- package/dist/migrations/appwriteToX.d.ts +0 -211
- package/dist/migrations/appwriteToX.js +0 -491
- package/dist/migrations/comprehensiveTransfer.d.ts +0 -147
- package/dist/migrations/comprehensiveTransfer.js +0 -1317
- package/dist/migrations/dataLoader.d.ts +0 -753
- package/dist/migrations/dataLoader.js +0 -1250
- package/dist/migrations/importController.d.ts +0 -23
- package/dist/migrations/importController.js +0 -268
- package/dist/migrations/importDataActions.d.ts +0 -50
- package/dist/migrations/importDataActions.js +0 -230
- package/dist/migrations/relationships.d.ts +0 -29
- package/dist/migrations/relationships.js +0 -204
- package/dist/migrations/services/DataTransformationService.d.ts +0 -55
- package/dist/migrations/services/DataTransformationService.js +0 -158
- package/dist/migrations/services/FileHandlerService.d.ts +0 -75
- package/dist/migrations/services/FileHandlerService.js +0 -236
- package/dist/migrations/services/ImportOrchestrator.d.ts +0 -97
- package/dist/migrations/services/ImportOrchestrator.js +0 -485
- package/dist/migrations/services/RateLimitManager.d.ts +0 -138
- package/dist/migrations/services/RateLimitManager.js +0 -279
- package/dist/migrations/services/RelationshipResolver.d.ts +0 -120
- package/dist/migrations/services/RelationshipResolver.js +0 -332
- package/dist/migrations/services/UserMappingService.d.ts +0 -109
- package/dist/migrations/services/UserMappingService.js +0 -277
- package/dist/migrations/services/ValidationService.d.ts +0 -74
- package/dist/migrations/services/ValidationService.js +0 -260
- package/dist/migrations/transfer.d.ts +0 -26
- package/dist/migrations/transfer.js +0 -608
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +0 -131
- package/dist/migrations/yaml/YamlImportConfigLoader.js +0 -383
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +0 -93
- package/dist/migrations/yaml/YamlImportIntegration.js +0 -341
- package/dist/migrations/yaml/generateImportSchemas.d.ts +0 -30
- package/dist/migrations/yaml/generateImportSchemas.js +0 -1327
- package/dist/schemas/authUser.d.ts +0 -24
- package/dist/schemas/authUser.js +0 -17
- package/dist/setup.d.ts +0 -2
- package/dist/setup.js +0 -5
- package/dist/setupCommands.d.ts +0 -58
- package/dist/setupCommands.js +0 -490
- package/dist/setupController.d.ts +0 -9
- package/dist/setupController.js +0 -34
- package/dist/shared/attributeMapper.d.ts +0 -20
- package/dist/shared/attributeMapper.js +0 -203
- package/dist/shared/backupMetadataSchema.d.ts +0 -94
- package/dist/shared/backupMetadataSchema.js +0 -38
- package/dist/shared/backupTracking.d.ts +0 -18
- package/dist/shared/backupTracking.js +0 -176
- package/dist/shared/confirmationDialogs.d.ts +0 -75
- package/dist/shared/confirmationDialogs.js +0 -236
- package/dist/shared/errorUtils.d.ts +0 -54
- package/dist/shared/errorUtils.js +0 -95
- package/dist/shared/functionManager.d.ts +0 -48
- package/dist/shared/functionManager.js +0 -348
- package/dist/shared/jsonSchemaGenerator.d.ts +0 -50
- package/dist/shared/jsonSchemaGenerator.js +0 -290
- package/dist/shared/logging.d.ts +0 -61
- package/dist/shared/logging.js +0 -116
- package/dist/shared/messageFormatter.d.ts +0 -39
- package/dist/shared/messageFormatter.js +0 -162
- package/dist/shared/migrationHelpers.d.ts +0 -61
- package/dist/shared/migrationHelpers.js +0 -145
- package/dist/shared/operationLogger.d.ts +0 -10
- package/dist/shared/operationLogger.js +0 -12
- package/dist/shared/operationQueue.d.ts +0 -40
- package/dist/shared/operationQueue.js +0 -311
- package/dist/shared/operationsTable.d.ts +0 -26
- package/dist/shared/operationsTable.js +0 -286
- package/dist/shared/operationsTableSchema.d.ts +0 -48
- package/dist/shared/operationsTableSchema.js +0 -35
- package/dist/shared/progressManager.d.ts +0 -62
- package/dist/shared/progressManager.js +0 -215
- package/dist/shared/pydanticModelGenerator.d.ts +0 -17
- package/dist/shared/pydanticModelGenerator.js +0 -615
- package/dist/shared/relationshipExtractor.d.ts +0 -56
- package/dist/shared/relationshipExtractor.js +0 -138
- package/dist/shared/schemaGenerator.d.ts +0 -40
- package/dist/shared/schemaGenerator.js +0 -556
- package/dist/shared/selectionDialogs.d.ts +0 -214
- package/dist/shared/selectionDialogs.js +0 -544
- package/dist/storage/backupCompression.d.ts +0 -20
- package/dist/storage/backupCompression.js +0 -67
- package/dist/storage/methods.d.ts +0 -32
- package/dist/storage/methods.js +0 -472
- package/dist/storage/schemas.d.ts +0 -842
- package/dist/storage/schemas.js +0 -175
- package/dist/tables/indexManager.d.ts +0 -65
- package/dist/tables/indexManager.js +0 -294
- package/dist/types.d.ts +0 -4
- package/dist/types.js +0 -3
- package/dist/users/methods.d.ts +0 -16
- package/dist/users/methods.js +0 -277
- package/dist/utils/ClientFactory.d.ts +0 -87
- package/dist/utils/ClientFactory.js +0 -212
- package/dist/utils/configDiscovery.d.ts +0 -78
- package/dist/utils/configDiscovery.js +0 -472
- package/dist/utils/configMigration.d.ts +0 -1
- package/dist/utils/configMigration.js +0 -261
- package/dist/utils/constantsGenerator.d.ts +0 -31
- package/dist/utils/constantsGenerator.js +0 -321
- package/dist/utils/dataConverters.d.ts +0 -46
- package/dist/utils/dataConverters.js +0 -139
- package/dist/utils/directoryUtils.d.ts +0 -22
- package/dist/utils/directoryUtils.js +0 -59
- package/dist/utils/getClientFromConfig.d.ts +0 -39
- package/dist/utils/getClientFromConfig.js +0 -199
- package/dist/utils/helperFunctions.d.ts +0 -63
- package/dist/utils/helperFunctions.js +0 -156
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -2
- package/dist/utils/loadConfigs.d.ts +0 -50
- package/dist/utils/loadConfigs.js +0 -358
- package/dist/utils/pathResolvers.d.ts +0 -53
- package/dist/utils/pathResolvers.js +0 -72
- package/dist/utils/projectConfig.d.ts +0 -122
- package/dist/utils/projectConfig.js +0 -206
- package/dist/utils/retryFailedPromises.d.ts +0 -2
- package/dist/utils/retryFailedPromises.js +0 -23
- package/dist/utils/sessionAuth.d.ts +0 -48
- package/dist/utils/sessionAuth.js +0 -164
- package/dist/utils/setupFiles.d.ts +0 -4
- package/dist/utils/setupFiles.js +0 -1192
- package/dist/utils/typeGuards.d.ts +0 -35
- package/dist/utils/typeGuards.js +0 -57
- package/dist/utils/validationRules.d.ts +0 -43
- package/dist/utils/validationRules.js +0 -42
- package/dist/utils/versionDetection.d.ts +0 -58
- package/dist/utils/versionDetection.js +0 -251
- package/dist/utils/yamlConverter.d.ts +0 -100
- package/dist/utils/yamlConverter.js +0 -428
- package/dist/utils/yamlLoader.d.ts +0 -70
- package/dist/utils/yamlLoader.js +0 -267
- package/dist/utilsController.d.ts +0 -107
- package/dist/utilsController.js +0 -873
- package/src/adapters/AdapterFactory.ts +0 -529
- package/src/adapters/DatabaseAdapter.ts +0 -319
- package/src/adapters/LegacyAdapter.ts +0 -844
- package/src/adapters/TablesDBAdapter.ts +0 -823
- package/src/config/ConfigManager.ts +0 -849
- package/src/config/README.md +0 -274
- package/src/config/configMigration.ts +0 -575
- package/src/config/configValidation.ts +0 -445
- package/src/config/index.ts +0 -10
- package/src/config/services/ConfigDiscoveryService.ts +0 -410
- package/src/config/services/ConfigLoaderService.ts +0 -732
- package/src/config/services/ConfigMergeService.ts +0 -388
- package/src/config/services/ConfigValidationService.ts +0 -394
- package/src/config/services/SessionAuthService.ts +0 -565
- package/src/config/services/__tests__/ConfigMergeService.test.ts +0 -351
- package/src/config/services/index.ts +0 -29
- package/src/config/yamlConfig.ts +0 -761
- package/src/functions/pathResolution.ts +0 -227
- package/src/functions/templates/count-docs-in-collection/package.json +0 -25
- package/src/functions/templates/count-docs-in-collection/tsconfig.json +0 -28
- package/src/functions/templates/hono-typescript/package.json +0 -26
- package/src/functions/templates/hono-typescript/tsconfig.json +0 -20
- package/src/functions/templates/typescript-node/package.json +0 -25
- package/src/functions/templates/typescript-node/tsconfig.json +0 -28
- package/src/shared/attributeMapper.ts +0 -229
- package/src/shared/errorUtils.ts +0 -110
- package/src/shared/functionManager.ts +0 -537
- package/src/shared/jsonSchemaGenerator.ts +0 -383
- package/src/shared/logging.ts +0 -149
- package/src/shared/messageFormatter.ts +0 -208
- package/src/shared/pydanticModelGenerator.ts +0 -618
- package/src/shared/schemaGenerator.ts +0 -644
- package/src/utils/ClientFactory.ts +0 -240
- package/src/utils/configDiscovery.ts +0 -557
- package/src/utils/constantsGenerator.ts +0 -369
- package/src/utils/dataConverters.ts +0 -159
- package/src/utils/directoryUtils.ts +0 -61
- package/src/utils/getClientFromConfig.ts +0 -257
- package/src/utils/helperFunctions.ts +0 -228
- package/src/utils/pathResolvers.ts +0 -81
- package/src/utils/projectConfig.ts +0 -340
- package/src/utils/retryFailedPromises.ts +0 -29
- package/src/utils/sessionAuth.ts +0 -230
- package/src/utils/typeGuards.ts +0 -65
- package/src/utils/validationRules.ts +0 -88
- package/src/utils/versionDetection.ts +0 -292
- package/src/utils/yamlConverter.ts +0 -542
- package/src/utils/yamlLoader.ts +0 -371
- package/tmp-sync-test/.appwrite/collections/TestCollection.yaml +0 -7
|
@@ -1,339 +1,377 @@
|
|
|
1
|
-
import { converterFunctions, tryAwaitWithRetry } from "appwrite-utils";
|
|
2
|
-
import {
|
|
3
|
-
Client,
|
|
4
|
-
Databases,
|
|
5
|
-
IndexType,
|
|
6
|
-
Query,
|
|
7
|
-
Storage,
|
|
8
|
-
Users,
|
|
9
|
-
type Models,
|
|
10
|
-
} from "node-appwrite";
|
|
11
|
-
import { InputFile } from "node-appwrite/file";
|
|
12
|
-
import { getAppwriteClient } from "
|
|
1
|
+
import { converterFunctions, tryAwaitWithRetry } from "appwrite-utils";
|
|
2
|
+
import {
|
|
3
|
+
Client,
|
|
4
|
+
Databases,
|
|
5
|
+
IndexType,
|
|
6
|
+
Query,
|
|
7
|
+
Storage,
|
|
8
|
+
Users,
|
|
9
|
+
type Models,
|
|
10
|
+
} from "node-appwrite";
|
|
11
|
+
import { InputFile } from "node-appwrite/file";
|
|
12
|
+
import { getAppwriteClient } from "appwrite-utils-helpers";
|
|
13
13
|
// Legacy attribute helpers retained only for local-to-local flows if needed
|
|
14
|
-
import { parseAttribute } from "appwrite-utils";
|
|
15
|
-
import chalk from "chalk";
|
|
16
|
-
import { fetchAllCollections } from "../collections/methods.js";
|
|
17
|
-
import { MessageFormatter } from "
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { getClient, getAdapter } from "../utils/getClientFromConfig.js";
|
|
14
|
+
import { parseAttribute } from "appwrite-utils";
|
|
15
|
+
import chalk from "chalk";
|
|
16
|
+
import { fetchAllCollections } from "../collections/methods.js";
|
|
17
|
+
import { MessageFormatter, mapToCreateAttributeParams } from "appwrite-utils-helpers";
|
|
18
|
+
import { ProgressManager } from "../shared/progressManager.js";
|
|
19
|
+
import { getClient, getAdapter } from "appwrite-utils-helpers";
|
|
21
20
|
import { diffTableColumns } from "../collections/tableOperations.js";
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
attempts
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
lastFileId
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
Query.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
)
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
);
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
let
|
|
183
|
-
let
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
lastFileId
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
Query.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* @param {Databases} localDb - The local database instance.
|
|
247
|
-
* @param {string} fromDbId - The ID of the source database.
|
|
248
|
-
* @param {string} targetDbId - The ID of the target database.
|
|
249
|
-
* @
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
21
|
+
import { type DatabaseAdapter } from "appwrite-utils-helpers";
|
|
22
|
+
|
|
23
|
+
export interface TransferOptions {
|
|
24
|
+
fromDb: Models.Database | undefined;
|
|
25
|
+
targetDb: Models.Database | undefined;
|
|
26
|
+
isRemote: boolean;
|
|
27
|
+
collections?: string[];
|
|
28
|
+
transferEndpoint?: string;
|
|
29
|
+
transferProject?: string;
|
|
30
|
+
transferKey?: string;
|
|
31
|
+
sourceBucket?: Models.Bucket;
|
|
32
|
+
targetBucket?: Models.Bucket;
|
|
33
|
+
transferUsers?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const transferStorageLocalToLocal = async (
|
|
37
|
+
storage: Storage,
|
|
38
|
+
fromBucketId: string,
|
|
39
|
+
toBucketId: string
|
|
40
|
+
) => {
|
|
41
|
+
MessageFormatter.info(
|
|
42
|
+
`Transferring files from ${fromBucketId} to ${toBucketId}`,
|
|
43
|
+
{ prefix: "Transfer" }
|
|
44
|
+
);
|
|
45
|
+
let lastFileId: string | undefined;
|
|
46
|
+
let fromFiles = await tryAwaitWithRetry(
|
|
47
|
+
async () => await storage.listFiles(fromBucketId, [Query.limit(100)])
|
|
48
|
+
);
|
|
49
|
+
const allFromFiles = fromFiles.files;
|
|
50
|
+
let numberOfFiles = 0;
|
|
51
|
+
|
|
52
|
+
const downloadFileWithRetry = async (bucketId: string, fileId: string) => {
|
|
53
|
+
let attempts = 3;
|
|
54
|
+
while (attempts > 0) {
|
|
55
|
+
try {
|
|
56
|
+
return await storage.getFileDownload(bucketId, fileId);
|
|
57
|
+
} catch (error) {
|
|
58
|
+
MessageFormatter.error(
|
|
59
|
+
`Error downloading file ${fileId}`,
|
|
60
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
61
|
+
{ prefix: "Transfer" }
|
|
62
|
+
);
|
|
63
|
+
attempts--;
|
|
64
|
+
if (attempts === 0) throw error;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
if (fromFiles.files.length < 100) {
|
|
70
|
+
for (const file of allFromFiles) {
|
|
71
|
+
const fileData = await tryAwaitWithRetry(
|
|
72
|
+
async () => await downloadFileWithRetry(file.bucketId, file.$id)
|
|
73
|
+
);
|
|
74
|
+
if (!fileData) {
|
|
75
|
+
MessageFormatter.error(
|
|
76
|
+
`Error downloading file ${file.$id}`,
|
|
77
|
+
undefined,
|
|
78
|
+
{ prefix: "Transfer" }
|
|
79
|
+
);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
const fileToCreate = InputFile.fromBuffer(
|
|
83
|
+
new Uint8Array(fileData),
|
|
84
|
+
file.name
|
|
85
|
+
);
|
|
86
|
+
MessageFormatter.progress(`Creating file: ${file.name}`, {
|
|
87
|
+
prefix: "Transfer",
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
await tryAwaitWithRetry(
|
|
91
|
+
async () =>
|
|
92
|
+
await storage.createFile(
|
|
93
|
+
toBucketId,
|
|
94
|
+
file.$id,
|
|
95
|
+
fileToCreate,
|
|
96
|
+
file.$permissions
|
|
97
|
+
)
|
|
98
|
+
);
|
|
99
|
+
} catch (error: any) {
|
|
100
|
+
// File already exists, so we can skip it
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
numberOfFiles++;
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
lastFileId = fromFiles.files[fromFiles.files.length - 1].$id;
|
|
107
|
+
while (lastFileId) {
|
|
108
|
+
const files = await tryAwaitWithRetry(
|
|
109
|
+
async () =>
|
|
110
|
+
await storage.listFiles(fromBucketId, [
|
|
111
|
+
Query.limit(100),
|
|
112
|
+
Query.cursorAfter(lastFileId!),
|
|
113
|
+
])
|
|
114
|
+
);
|
|
115
|
+
allFromFiles.push(...files.files);
|
|
116
|
+
if (files.files.length < 100) {
|
|
117
|
+
lastFileId = undefined;
|
|
118
|
+
} else {
|
|
119
|
+
lastFileId = files.files[files.files.length - 1].$id;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
for (const file of allFromFiles) {
|
|
123
|
+
const fileData = await tryAwaitWithRetry(
|
|
124
|
+
async () => await downloadFileWithRetry(file.bucketId, file.$id)
|
|
125
|
+
);
|
|
126
|
+
if (!fileData) {
|
|
127
|
+
MessageFormatter.error(
|
|
128
|
+
`Error downloading file ${file.$id}`,
|
|
129
|
+
undefined,
|
|
130
|
+
{ prefix: "Transfer" }
|
|
131
|
+
);
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const fileToCreate = InputFile.fromBuffer(
|
|
135
|
+
new Uint8Array(fileData),
|
|
136
|
+
file.name
|
|
137
|
+
);
|
|
138
|
+
try {
|
|
139
|
+
await tryAwaitWithRetry(
|
|
140
|
+
async () =>
|
|
141
|
+
await storage.createFile(
|
|
142
|
+
toBucketId,
|
|
143
|
+
file.$id,
|
|
144
|
+
fileToCreate,
|
|
145
|
+
file.$permissions
|
|
146
|
+
)
|
|
147
|
+
);
|
|
148
|
+
} catch (error: any) {
|
|
149
|
+
// File already exists, so we can skip it
|
|
150
|
+
MessageFormatter.warning(
|
|
151
|
+
`File ${file.$id} already exists, skipping...`,
|
|
152
|
+
{ prefix: "Transfer" }
|
|
153
|
+
);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
numberOfFiles++;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
MessageFormatter.success(
|
|
161
|
+
`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`,
|
|
162
|
+
{ prefix: "Transfer" }
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const transferStorageLocalToRemote = async (
|
|
167
|
+
localStorage: Storage,
|
|
168
|
+
endpoint: string,
|
|
169
|
+
projectId: string,
|
|
170
|
+
apiKey: string,
|
|
171
|
+
fromBucketId: string,
|
|
172
|
+
toBucketId: string
|
|
173
|
+
) => {
|
|
174
|
+
MessageFormatter.info(
|
|
175
|
+
`Transferring files from current storage ${fromBucketId} to ${endpoint} bucket ${toBucketId}`,
|
|
176
|
+
{ prefix: "Transfer" }
|
|
177
|
+
);
|
|
178
|
+
const client = getAppwriteClient(endpoint, projectId, apiKey);
|
|
179
|
+
const remoteStorage = new Storage(client);
|
|
180
|
+
let numberOfFiles = 0;
|
|
181
|
+
let lastFileId: string | undefined;
|
|
182
|
+
let fromFiles = await tryAwaitWithRetry(
|
|
183
|
+
async () => await localStorage.listFiles(fromBucketId, [Query.limit(100)])
|
|
184
|
+
);
|
|
185
|
+
const allFromFiles = fromFiles.files;
|
|
186
|
+
if (fromFiles.files.length === 100) {
|
|
187
|
+
lastFileId = fromFiles.files[fromFiles.files.length - 1].$id;
|
|
188
|
+
while (lastFileId) {
|
|
189
|
+
const files = await tryAwaitWithRetry(
|
|
190
|
+
async () =>
|
|
191
|
+
await localStorage.listFiles(fromBucketId, [
|
|
192
|
+
Query.limit(100),
|
|
193
|
+
Query.cursorAfter(lastFileId!),
|
|
194
|
+
])
|
|
195
|
+
);
|
|
196
|
+
allFromFiles.push(...files.files);
|
|
197
|
+
if (files.files.length < 100) {
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
lastFileId = files.files[files.files.length - 1].$id;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
for (const file of allFromFiles) {
|
|
205
|
+
const fileData = await tryAwaitWithRetry(
|
|
206
|
+
async () => await localStorage.getFileDownload(file.bucketId, file.$id)
|
|
207
|
+
);
|
|
208
|
+
const fileToCreate = InputFile.fromBuffer(
|
|
209
|
+
new Uint8Array(fileData),
|
|
210
|
+
file.name
|
|
211
|
+
);
|
|
212
|
+
try {
|
|
213
|
+
await tryAwaitWithRetry(
|
|
214
|
+
async () =>
|
|
215
|
+
await remoteStorage.createFile(
|
|
216
|
+
toBucketId,
|
|
217
|
+
file.$id,
|
|
218
|
+
fileToCreate,
|
|
219
|
+
file.$permissions
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
} catch (error: any) {
|
|
223
|
+
// File already exists, so we can skip it
|
|
224
|
+
MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, {
|
|
225
|
+
prefix: "Transfer",
|
|
226
|
+
});
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
numberOfFiles++;
|
|
230
|
+
}
|
|
231
|
+
MessageFormatter.success(
|
|
232
|
+
`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`,
|
|
233
|
+
{ prefix: "Transfer" }
|
|
234
|
+
);
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// Document transfer functions moved to collections/methods.ts with enhanced UX
|
|
238
|
+
|
|
239
|
+
// Remote document transfer functions moved to collections/methods.ts with enhanced UX
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Transfers all tables/collections and documents from one local database to another local database.
|
|
243
|
+
* Uses the DatabaseAdapter for unified TablesDB / legacy support.
|
|
244
|
+
*
|
|
245
|
+
* @param {Databases} localDb - The local database instance (kept for signature compat).
|
|
246
|
+
* @param {string} fromDbId - The ID of the source database.
|
|
247
|
+
* @param {string} targetDbId - The ID of the target database.
|
|
248
|
+
* @param {string[]} collectionIds - Optional filter: specific table/collection IDs to transfer. undefined = all, empty array = none.
|
|
249
|
+
* @param {DatabaseAdapter} adapter - The database adapter (TablesDB or Legacy).
|
|
250
|
+
* @return {Promise<void>} A promise that resolves when the transfer is complete.
|
|
251
|
+
*/
|
|
252
|
+
export const transferDatabaseLocalToLocal = async (
|
|
253
|
+
localDb: Databases,
|
|
254
|
+
fromDbId: string,
|
|
255
|
+
targetDbId: string,
|
|
256
|
+
collectionIds?: string[],
|
|
257
|
+
adapter?: DatabaseAdapter
|
|
258
|
+
) => {
|
|
259
|
+
if (!adapter) {
|
|
260
|
+
throw new Error("DatabaseAdapter is required for transferDatabaseLocalToLocal");
|
|
261
|
+
}
|
|
262
|
+
const dbAdapter: DatabaseAdapter = adapter;
|
|
263
|
+
|
|
264
|
+
MessageFormatter.info(
|
|
265
|
+
`Starting database transfer from ${fromDbId} to ${targetDbId} (mode: ${dbAdapter.getApiMode()})`,
|
|
266
|
+
{ prefix: "Transfer" }
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// Get all tables/collections from source database via adapter
|
|
270
|
+
const sourceListRes = await dbAdapter.listTables({ databaseId: fromDbId, queries: [Query.limit(500)] });
|
|
271
|
+
let sourceTables: any[] = sourceListRes.tables || sourceListRes.collections || sourceListRes.data || [];
|
|
272
|
+
|
|
273
|
+
// Filter by collectionIds if provided (match by $id or by name)
|
|
274
|
+
if (collectionIds !== undefined) {
|
|
275
|
+
if (collectionIds.length === 0) {
|
|
276
|
+
MessageFormatter.info("No tables/collections selected for transfer, skipping.", { prefix: "Transfer" });
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
const idSet = new Set(collectionIds);
|
|
280
|
+
sourceTables = sourceTables.filter((c: any) => idSet.has(c.$id) || idSet.has(c.name));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
MessageFormatter.info(
|
|
284
|
+
`Found ${sourceTables.length} tables/collections in source database`,
|
|
285
|
+
{ prefix: "Transfer" }
|
|
286
|
+
);
|
|
287
|
+
|
|
288
|
+
// Process each table/collection
|
|
289
|
+
for (const table of sourceTables) {
|
|
290
|
+
MessageFormatter.processing(
|
|
291
|
+
`Processing table: ${table.name} (${table.$id})`,
|
|
292
|
+
{ prefix: "Transfer" }
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
try {
|
|
296
|
+
// Check if table exists in target via adapter
|
|
297
|
+
let targetTableId = table.$id;
|
|
298
|
+
let targetTableData: any;
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
const existingRes = await dbAdapter.getTable({ databaseId: targetDbId, tableId: table.$id });
|
|
302
|
+
targetTableData = existingRes.data || (existingRes.tables && existingRes.tables[0]);
|
|
303
|
+
|
|
304
|
+
if (targetTableData) {
|
|
305
|
+
MessageFormatter.info(
|
|
306
|
+
`Table ${table.name} exists in target database`,
|
|
307
|
+
{ prefix: "Transfer" }
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
// Update table if needed
|
|
311
|
+
const securityField = table.rowSecurity ?? table.documentSecurity ?? false;
|
|
312
|
+
const targetSecurity = targetTableData.rowSecurity ?? targetTableData.documentSecurity ?? false;
|
|
313
|
+
if (
|
|
314
|
+
targetTableData.name !== table.name ||
|
|
315
|
+
JSON.stringify(targetTableData.$permissions) !== JSON.stringify(table.$permissions) ||
|
|
316
|
+
targetSecurity !== securityField ||
|
|
317
|
+
targetTableData.enabled !== table.enabled
|
|
318
|
+
) {
|
|
319
|
+
await tryAwaitWithRetry(async () =>
|
|
320
|
+
dbAdapter.updateTable({
|
|
321
|
+
databaseId: targetDbId,
|
|
322
|
+
id: table.$id,
|
|
323
|
+
name: table.name,
|
|
324
|
+
permissions: table.$permissions,
|
|
325
|
+
documentSecurity: table.documentSecurity,
|
|
326
|
+
rowSecurity: table.rowSecurity,
|
|
327
|
+
enabled: table.enabled,
|
|
328
|
+
})
|
|
329
|
+
);
|
|
330
|
+
MessageFormatter.success(
|
|
331
|
+
`Table ${table.name} updated`,
|
|
332
|
+
{ prefix: "Transfer" }
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
} catch {
|
|
337
|
+
// Table does not exist in target, create it
|
|
338
|
+
targetTableData = null;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (!targetTableData) {
|
|
342
|
+
MessageFormatter.progress(
|
|
343
|
+
`Creating table ${table.name} in target database...`,
|
|
344
|
+
{ prefix: "Transfer" }
|
|
345
|
+
);
|
|
346
|
+
const createRes = await tryAwaitWithRetry(async () =>
|
|
347
|
+
dbAdapter.createTable({
|
|
348
|
+
databaseId: targetDbId,
|
|
349
|
+
id: table.$id,
|
|
350
|
+
name: table.name,
|
|
351
|
+
permissions: table.$permissions,
|
|
352
|
+
documentSecurity: table.documentSecurity,
|
|
353
|
+
rowSecurity: table.rowSecurity,
|
|
354
|
+
enabled: table.enabled,
|
|
355
|
+
})
|
|
356
|
+
);
|
|
357
|
+
targetTableData = createRes.data || (createRes.tables && createRes.tables[0]);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// Create attributes via adapter
|
|
361
|
+
MessageFormatter.info(`Creating attributes for ${table.name} via adapter...`, { prefix: 'Transfer' });
|
|
362
|
+
|
|
363
|
+
// Fetch existing attributes in target to skip already-created ones
|
|
364
|
+
const targetTableRes = await dbAdapter.getTable({ databaseId: targetDbId, tableId: targetTableId });
|
|
365
|
+
const targetInfo = targetTableRes.data || (targetTableRes.tables && targetTableRes.tables[0]);
|
|
366
|
+
const existingAttrs = targetInfo?.attributes || targetInfo?.columns || [];
|
|
367
|
+
const existingKeys = new Set(existingAttrs.map((a: any) => a.key || a.$id));
|
|
368
|
+
|
|
369
|
+
const uniformAttrs = (table.attributes || []).map((attr: any) => parseAttribute(attr as any));
|
|
333
370
|
const nonRel = uniformAttrs.filter((a: any) => a.type !== 'relationship');
|
|
334
371
|
for (const attr of nonRel) {
|
|
335
|
-
|
|
336
|
-
|
|
372
|
+
if (existingKeys.has(attr.key)) continue;
|
|
373
|
+
const params = mapToCreateAttributeParams(attr as any, { databaseId: targetDbId, tableId: targetTableId });
|
|
374
|
+
await dbAdapter.createAttribute(params);
|
|
337
375
|
await new Promise((r) => setTimeout(r, 150));
|
|
338
376
|
}
|
|
339
377
|
|
|
@@ -343,8 +381,9 @@ export const transferDatabaseLocalToLocal = async (
|
|
|
343
381
|
let lastStatus = '';
|
|
344
382
|
while (Date.now() - start < maxWait) {
|
|
345
383
|
try {
|
|
346
|
-
const tableRes = await
|
|
347
|
-
const
|
|
384
|
+
const tableRes = await dbAdapter.getTable({ databaseId: targetDbId, tableId: targetTableId });
|
|
385
|
+
const tInfo = tableRes.data || (tableRes.tables && tableRes.tables[0]);
|
|
386
|
+
const attrs = tInfo?.attributes || tInfo?.columns || [];
|
|
348
387
|
const found = attrs.find((a: any) => a.key === attr.key);
|
|
349
388
|
if (found) {
|
|
350
389
|
if (found.status === 'available') break;
|
|
@@ -366,17 +405,18 @@ export const transferDatabaseLocalToLocal = async (
|
|
|
366
405
|
// Relationship attributes
|
|
367
406
|
const rels = uniformAttrs.filter((a: any) => a.type === 'relationship');
|
|
368
407
|
for (const attr of rels) {
|
|
369
|
-
|
|
370
|
-
|
|
408
|
+
if (existingKeys.has(attr.key)) continue;
|
|
409
|
+
const params = mapToCreateAttributeParams(attr as any, { databaseId: targetDbId, tableId: targetTableId });
|
|
410
|
+
await dbAdapter.createAttribute(params);
|
|
371
411
|
await new Promise((r) => setTimeout(r, 150));
|
|
372
412
|
}
|
|
373
|
-
|
|
413
|
+
|
|
374
414
|
// Handle indexes via adapter (create or update)
|
|
375
|
-
for (const idx of
|
|
415
|
+
for (const idx of (table.indexes || [])) {
|
|
376
416
|
try {
|
|
377
|
-
await
|
|
417
|
+
await dbAdapter.createIndex({
|
|
378
418
|
databaseId: targetDbId,
|
|
379
|
-
tableId:
|
|
419
|
+
tableId: targetTableId,
|
|
380
420
|
key: (idx as any).key,
|
|
381
421
|
type: (idx as any).type,
|
|
382
422
|
attributes: (idx as any).attributes,
|
|
@@ -387,10 +427,10 @@ export const transferDatabaseLocalToLocal = async (
|
|
|
387
427
|
} catch (e) {
|
|
388
428
|
// Try update path by deleting and recreating if necessary
|
|
389
429
|
try {
|
|
390
|
-
await
|
|
391
|
-
await
|
|
430
|
+
await dbAdapter.deleteIndex({ databaseId: targetDbId, tableId: targetTableId, key: (idx as any).key });
|
|
431
|
+
await dbAdapter.createIndex({
|
|
392
432
|
databaseId: targetDbId,
|
|
393
|
-
tableId:
|
|
433
|
+
tableId: targetTableId,
|
|
394
434
|
key: (idx as any).key,
|
|
395
435
|
type: (idx as any).type,
|
|
396
436
|
attributes: (idx as any).attributes,
|
|
@@ -403,106 +443,111 @@ export const transferDatabaseLocalToLocal = async (
|
|
|
403
443
|
}
|
|
404
444
|
}
|
|
405
445
|
}
|
|
406
|
-
|
|
407
|
-
// Transfer documents
|
|
408
|
-
const { transferDocumentsBetweenDbsLocalToLocal } = await import(
|
|
409
|
-
"../collections/
|
|
410
|
-
);
|
|
411
|
-
await transferDocumentsBetweenDbsLocalToLocal(
|
|
412
|
-
|
|
413
|
-
fromDbId,
|
|
414
|
-
targetDbId,
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
);
|
|
418
|
-
} catch (error) {
|
|
419
|
-
MessageFormatter.error(
|
|
420
|
-
`Error processing
|
|
421
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
422
|
-
{ prefix: "Transfer" }
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
|
|
428
|
-
export const transferDatabaseLocalToRemote = async (
|
|
429
|
-
localDb: Databases,
|
|
430
|
-
endpoint: string,
|
|
431
|
-
projectId: string,
|
|
432
|
-
apiKey: string,
|
|
433
|
-
fromDbId: string,
|
|
434
|
-
toDbId: string
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
targetCollection
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
446
|
+
|
|
447
|
+
// Transfer documents/rows via adapter
|
|
448
|
+
const { transferDocumentsBetweenDbsLocalToLocal } = await import(
|
|
449
|
+
"../collections/transferOperations.js"
|
|
450
|
+
);
|
|
451
|
+
await transferDocumentsBetweenDbsLocalToLocal(
|
|
452
|
+
dbAdapter,
|
|
453
|
+
fromDbId,
|
|
454
|
+
targetDbId,
|
|
455
|
+
table.$id,
|
|
456
|
+
targetTableId
|
|
457
|
+
);
|
|
458
|
+
} catch (error) {
|
|
459
|
+
MessageFormatter.error(
|
|
460
|
+
`Error processing table ${table.name}`,
|
|
461
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
462
|
+
{ prefix: "Transfer" }
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
export const transferDatabaseLocalToRemote = async (
|
|
469
|
+
localDb: Databases,
|
|
470
|
+
endpoint: string,
|
|
471
|
+
projectId: string,
|
|
472
|
+
apiKey: string,
|
|
473
|
+
fromDbId: string,
|
|
474
|
+
toDbId: string,
|
|
475
|
+
collectionIds?: string[]
|
|
476
|
+
) => {
|
|
477
|
+
const client = getAppwriteClient(endpoint, projectId, apiKey);
|
|
478
|
+
const remoteDb = new Databases(client);
|
|
479
|
+
|
|
480
|
+
// Get all collections from source database
|
|
481
|
+
let sourceCollections = await fetchAllCollections(fromDbId, localDb);
|
|
482
|
+
if (collectionIds && collectionIds.length > 0) {
|
|
483
|
+
const idSet = new Set(collectionIds);
|
|
484
|
+
sourceCollections = sourceCollections.filter((c) => idSet.has(c.$id));
|
|
485
|
+
}
|
|
486
|
+
MessageFormatter.info(
|
|
487
|
+
`Found ${sourceCollections.length} collections in source database`,
|
|
488
|
+
{ prefix: "Transfer" }
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
// Process each collection
|
|
492
|
+
for (const collection of sourceCollections) {
|
|
493
|
+
MessageFormatter.processing(
|
|
494
|
+
`Processing collection: ${collection.name} (${collection.$id})`,
|
|
495
|
+
{ prefix: "Transfer" }
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
try {
|
|
499
|
+
// Create or update collection in target
|
|
500
|
+
let targetCollection: Models.Collection;
|
|
501
|
+
const existingCollection = await tryAwaitWithRetry(async () =>
|
|
502
|
+
remoteDb.listCollections(toDbId, [Query.equal("$id", collection.$id)])
|
|
503
|
+
);
|
|
504
|
+
|
|
505
|
+
if (existingCollection.collections.length > 0) {
|
|
506
|
+
targetCollection = existingCollection.collections[0];
|
|
507
|
+
MessageFormatter.info(
|
|
508
|
+
`Collection ${collection.name} exists in remote database`,
|
|
509
|
+
{ prefix: "Transfer" }
|
|
510
|
+
);
|
|
511
|
+
|
|
512
|
+
// Update collection if needed
|
|
513
|
+
if (
|
|
514
|
+
targetCollection.name !== collection.name ||
|
|
515
|
+
targetCollection.$permissions !== collection.$permissions ||
|
|
516
|
+
targetCollection.documentSecurity !== collection.documentSecurity ||
|
|
517
|
+
targetCollection.enabled !== collection.enabled
|
|
518
|
+
) {
|
|
519
|
+
targetCollection = await tryAwaitWithRetry(async () =>
|
|
520
|
+
remoteDb.updateCollection(
|
|
521
|
+
toDbId,
|
|
522
|
+
collection.$id,
|
|
523
|
+
collection.name,
|
|
524
|
+
collection.$permissions,
|
|
525
|
+
collection.documentSecurity,
|
|
526
|
+
collection.enabled
|
|
527
|
+
)
|
|
528
|
+
);
|
|
529
|
+
MessageFormatter.success(
|
|
530
|
+
`Collection ${collection.name} updated`,
|
|
531
|
+
{ prefix: "Transfer" }
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
} else {
|
|
535
|
+
MessageFormatter.progress(
|
|
536
|
+
`Creating collection ${collection.name} in remote database...`,
|
|
537
|
+
{ prefix: "Transfer" }
|
|
538
|
+
);
|
|
539
|
+
targetCollection = await tryAwaitWithRetry(async () =>
|
|
540
|
+
remoteDb.createCollection(
|
|
541
|
+
toDbId,
|
|
542
|
+
collection.$id,
|
|
543
|
+
collection.name,
|
|
544
|
+
collection.$permissions,
|
|
545
|
+
collection.documentSecurity,
|
|
546
|
+
collection.enabled
|
|
547
|
+
)
|
|
548
|
+
);
|
|
549
|
+
}
|
|
550
|
+
|
|
506
551
|
// Create/Update attributes via adapter (prefer adapter for remote)
|
|
507
552
|
const { adapter: remoteAdapter } = await getAdapter(endpoint, projectId, apiKey, 'auto');
|
|
508
553
|
MessageFormatter.info(`Creating attributes for ${collection.name} via adapter...`, { prefix: 'Transfer' });
|
|
@@ -551,13 +596,13 @@ export const transferDatabaseLocalToRemote = async (
|
|
|
551
596
|
for (const a of rUpdate) { const p = mapToCreateAttributeParams(a as any, { databaseId: toDbId, tableId: collection.$id }); await (remoteAdapter as DatabaseAdapter).updateAttribute(p as any); await new Promise((r)=>setTimeout(r,150)); }
|
|
552
597
|
for (const a of rCreate) { const p = mapToCreateAttributeParams(a as any, { databaseId: toDbId, tableId: collection.$id }); await (remoteAdapter as DatabaseAdapter).createAttribute(p); await new Promise((r)=>setTimeout(r,150)); }
|
|
553
598
|
}
|
|
554
|
-
|
|
555
|
-
// Handle indexes with enhanced status checking
|
|
556
|
-
MessageFormatter.info(
|
|
557
|
-
`Creating indexes for collection ${collection.name} with enhanced monitoring...`,
|
|
558
|
-
{ prefix: "Transfer" }
|
|
559
|
-
);
|
|
560
|
-
|
|
599
|
+
|
|
600
|
+
// Handle indexes with enhanced status checking
|
|
601
|
+
MessageFormatter.info(
|
|
602
|
+
`Creating indexes for collection ${collection.name} with enhanced monitoring...`,
|
|
603
|
+
{ prefix: "Transfer" }
|
|
604
|
+
);
|
|
605
|
+
|
|
561
606
|
// Create indexes via adapter
|
|
562
607
|
for (const idx of (collection.indexes as any[]) || []) {
|
|
563
608
|
try {
|
|
@@ -574,495 +619,495 @@ export const transferDatabaseLocalToRemote = async (
|
|
|
574
619
|
MessageFormatter.error(`Failed to create index ${idx.key}`, e instanceof Error ? e : new Error(String(e)), { prefix: 'Transfer' });
|
|
575
620
|
}
|
|
576
621
|
}
|
|
577
|
-
|
|
578
|
-
// Transfer documents
|
|
579
|
-
const { transferDocumentsBetweenDbsLocalToRemote } = await import(
|
|
580
|
-
"../collections/methods.js"
|
|
581
|
-
);
|
|
582
|
-
await transferDocumentsBetweenDbsLocalToRemote(
|
|
583
|
-
localDb,
|
|
584
|
-
endpoint,
|
|
585
|
-
projectId,
|
|
586
|
-
apiKey,
|
|
587
|
-
fromDbId,
|
|
588
|
-
toDbId,
|
|
589
|
-
collection.$id,
|
|
590
|
-
targetCollection.$id
|
|
591
|
-
);
|
|
592
|
-
} catch (error) {
|
|
593
|
-
MessageFormatter.error(
|
|
594
|
-
`Error processing collection ${collection.name}`,
|
|
595
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
596
|
-
{ prefix: "Transfer" }
|
|
597
|
-
);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
};
|
|
601
|
-
|
|
602
|
-
export const transferUsersLocalToRemote = async (
|
|
603
|
-
localUsers: Users,
|
|
604
|
-
endpoint: string,
|
|
605
|
-
projectId: string,
|
|
606
|
-
apiKey: string
|
|
607
|
-
) => {
|
|
608
|
-
MessageFormatter.info(
|
|
609
|
-
"Starting user transfer to remote instance...",
|
|
610
|
-
{ prefix: "Transfer" }
|
|
611
|
-
);
|
|
612
|
-
|
|
613
|
-
const client = getClient(endpoint, projectId, apiKey);
|
|
614
|
-
const remoteUsers = new Users(client);
|
|
615
|
-
|
|
616
|
-
let totalTransferred = 0;
|
|
617
|
-
let lastId: string | undefined;
|
|
618
|
-
|
|
619
|
-
while (true) {
|
|
620
|
-
const queries = [Query.limit(100)];
|
|
621
|
-
if (lastId) {
|
|
622
|
-
queries.push(Query.cursorAfter(lastId));
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
const usersList = await tryAwaitWithRetry(async () =>
|
|
626
|
-
localUsers.list(queries)
|
|
627
|
-
);
|
|
628
|
-
|
|
629
|
-
if (usersList.users.length === 0) {
|
|
630
|
-
break;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
for (const user of usersList.users) {
|
|
634
|
-
try {
|
|
635
|
-
// Check if user already exists in remote
|
|
636
|
-
let remoteUser: Models.User<Models.Preferences> | undefined;
|
|
637
|
-
try {
|
|
638
|
-
remoteUser = await tryAwaitWithRetry(async () =>
|
|
639
|
-
remoteUsers.get(user.$id)
|
|
640
|
-
);
|
|
641
|
-
|
|
642
|
-
// If user exists, update only the differences
|
|
643
|
-
if (remoteUser) {
|
|
644
|
-
MessageFormatter.info(
|
|
645
|
-
`User ${user.$id} exists, checking for updates...`,
|
|
646
|
-
{ prefix: "Transfer" }
|
|
647
|
-
);
|
|
648
|
-
let hasUpdates = false;
|
|
649
|
-
|
|
650
|
-
// Update name if different
|
|
651
|
-
if (remoteUser.name !== user.name) {
|
|
652
|
-
await tryAwaitWithRetry(async () =>
|
|
653
|
-
remoteUsers.updateName(user.$id, user.name)
|
|
654
|
-
);
|
|
655
|
-
MessageFormatter.success(
|
|
656
|
-
`Updated name for user ${user.$id}`,
|
|
657
|
-
{ prefix: "Transfer" }
|
|
658
|
-
);
|
|
659
|
-
hasUpdates = true;
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
// Update email if different
|
|
663
|
-
if (remoteUser.email !== user.email) {
|
|
664
|
-
await tryAwaitWithRetry(async () =>
|
|
665
|
-
remoteUsers.updateEmail(user.$id, user.email)
|
|
666
|
-
);
|
|
667
|
-
MessageFormatter.success(
|
|
668
|
-
`Updated email for user ${user.$id}`,
|
|
669
|
-
{ prefix: "Transfer" }
|
|
670
|
-
);
|
|
671
|
-
hasUpdates = true;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
// Update phone if different
|
|
675
|
-
const normalizedLocalPhone = user.phone
|
|
676
|
-
? converterFunctions.convertPhoneStringToUSInternational(user.phone)
|
|
677
|
-
: undefined;
|
|
678
|
-
if (remoteUser.phone !== normalizedLocalPhone) {
|
|
679
|
-
if (normalizedLocalPhone) {
|
|
680
|
-
await tryAwaitWithRetry(async () =>
|
|
681
|
-
remoteUsers.updatePhone(user.$id, normalizedLocalPhone)
|
|
682
|
-
);
|
|
683
|
-
}
|
|
684
|
-
MessageFormatter.success(
|
|
685
|
-
`Updated phone for user ${user.$id}`,
|
|
686
|
-
{ prefix: "Transfer" }
|
|
687
|
-
);
|
|
688
|
-
hasUpdates = true;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
// Update preferences if different
|
|
692
|
-
if (JSON.stringify(remoteUser.prefs) !== JSON.stringify(user.prefs)) {
|
|
693
|
-
await tryAwaitWithRetry(async () =>
|
|
694
|
-
remoteUsers.updatePrefs(user.$id, user.prefs)
|
|
695
|
-
);
|
|
696
|
-
MessageFormatter.success(
|
|
697
|
-
`Updated preferences for user ${user.$id}`,
|
|
698
|
-
{ prefix: "Transfer" }
|
|
699
|
-
);
|
|
700
|
-
hasUpdates = true;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// Update labels if different
|
|
704
|
-
if (JSON.stringify(remoteUser.labels) !== JSON.stringify(user.labels)) {
|
|
705
|
-
await tryAwaitWithRetry(async () =>
|
|
706
|
-
remoteUsers.updateLabels(user.$id, user.labels)
|
|
707
|
-
);
|
|
708
|
-
MessageFormatter.success(
|
|
709
|
-
`Updated labels for user ${user.$id}`,
|
|
710
|
-
{ prefix: "Transfer" }
|
|
711
|
-
);
|
|
712
|
-
hasUpdates = true;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
// Update email verification if different
|
|
716
|
-
if (remoteUser.emailVerification !== user.emailVerification) {
|
|
717
|
-
await tryAwaitWithRetry(async () =>
|
|
718
|
-
remoteUsers.updateEmailVerification(user.$id, user.emailVerification)
|
|
719
|
-
);
|
|
720
|
-
MessageFormatter.success(
|
|
721
|
-
`Updated email verification for user ${user.$id}`,
|
|
722
|
-
{ prefix: "Transfer" }
|
|
723
|
-
);
|
|
724
|
-
hasUpdates = true;
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
// Update phone verification if different
|
|
728
|
-
if (remoteUser.phoneVerification !== user.phoneVerification) {
|
|
729
|
-
await tryAwaitWithRetry(async () =>
|
|
730
|
-
remoteUsers.updatePhoneVerification(user.$id, user.phoneVerification)
|
|
731
|
-
);
|
|
732
|
-
MessageFormatter.success(
|
|
733
|
-
`Updated phone verification for user ${user.$id}`,
|
|
734
|
-
{ prefix: "Transfer" }
|
|
735
|
-
);
|
|
736
|
-
hasUpdates = true;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
// Update status if different
|
|
740
|
-
if (remoteUser.status !== user.status) {
|
|
741
|
-
await tryAwaitWithRetry(async () =>
|
|
742
|
-
remoteUsers.updateStatus(user.$id, user.status)
|
|
743
|
-
);
|
|
744
|
-
MessageFormatter.success(
|
|
745
|
-
`Updated status for user ${user.$id}`,
|
|
746
|
-
{ prefix: "Transfer" }
|
|
747
|
-
);
|
|
748
|
-
hasUpdates = true;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
if (!hasUpdates) {
|
|
752
|
-
MessageFormatter.info(
|
|
753
|
-
`User ${user.$id} is already up to date, skipping...`,
|
|
754
|
-
{ prefix: "Transfer" }
|
|
755
|
-
);
|
|
756
|
-
} else {
|
|
757
|
-
totalTransferred++;
|
|
758
|
-
MessageFormatter.success(
|
|
759
|
-
`Updated user ${user.$id}`,
|
|
760
|
-
{ prefix: "Transfer" }
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
continue;
|
|
764
|
-
}
|
|
765
|
-
} catch (error: any) {
|
|
766
|
-
// User doesn't exist, proceed with creation
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
const phone = user.phone
|
|
770
|
-
? converterFunctions.convertPhoneStringToUSInternational(user.phone)
|
|
771
|
-
: undefined;
|
|
772
|
-
|
|
773
|
-
// Handle user creation based on hash type
|
|
774
|
-
if (user.hash && user.password) {
|
|
775
|
-
// User has a hashed password - recreate with proper hash method
|
|
776
|
-
const hashType = user.hash.toLowerCase();
|
|
777
|
-
const hashedPassword = user.password; // This is already hashed
|
|
778
|
-
const hashOptions = (user.hashOptions as Record<string, any>) || {};
|
|
779
|
-
|
|
780
|
-
try {
|
|
781
|
-
switch (hashType) {
|
|
782
|
-
case "argon2":
|
|
783
|
-
await tryAwaitWithRetry(async () =>
|
|
784
|
-
remoteUsers.createArgon2User(
|
|
785
|
-
user.$id,
|
|
786
|
-
user.email,
|
|
787
|
-
hashedPassword,
|
|
788
|
-
user.name
|
|
789
|
-
)
|
|
790
|
-
);
|
|
791
|
-
break;
|
|
792
|
-
|
|
793
|
-
case "bcrypt":
|
|
794
|
-
await tryAwaitWithRetry(async () =>
|
|
795
|
-
remoteUsers.createBcryptUser(
|
|
796
|
-
user.$id,
|
|
797
|
-
user.email,
|
|
798
|
-
hashedPassword,
|
|
799
|
-
user.name
|
|
800
|
-
)
|
|
801
|
-
);
|
|
802
|
-
break;
|
|
803
|
-
|
|
804
|
-
case "scrypt":
|
|
805
|
-
// Scrypt requires additional parameters from hashOptions
|
|
806
|
-
const salt =
|
|
807
|
-
typeof hashOptions.salt === "string" ? hashOptions.salt : "";
|
|
808
|
-
const costCpu =
|
|
809
|
-
typeof hashOptions.costCpu === "number"
|
|
810
|
-
? hashOptions.costCpu
|
|
811
|
-
: 32768;
|
|
812
|
-
const costMemory =
|
|
813
|
-
typeof hashOptions.costMemory === "number"
|
|
814
|
-
? hashOptions.costMemory
|
|
815
|
-
: 14;
|
|
816
|
-
const costParallel =
|
|
817
|
-
typeof hashOptions.costParallel === "number"
|
|
818
|
-
? hashOptions.costParallel
|
|
819
|
-
: 1;
|
|
820
|
-
const length =
|
|
821
|
-
typeof hashOptions.length === "number"
|
|
822
|
-
? hashOptions.length
|
|
823
|
-
: 64;
|
|
824
|
-
|
|
825
|
-
// Warn if using default values due to missing hash options
|
|
826
|
-
if (
|
|
827
|
-
!hashOptions.salt ||
|
|
828
|
-
typeof hashOptions.costCpu !== "number"
|
|
829
|
-
) {
|
|
830
|
-
MessageFormatter.warning(
|
|
831
|
-
`User ${user.$id}: Using default Scrypt parameters due to missing hashOptions`,
|
|
832
|
-
{ prefix: "Transfer" }
|
|
833
|
-
);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
await tryAwaitWithRetry(async () =>
|
|
837
|
-
remoteUsers.createScryptUser(
|
|
838
|
-
user.$id,
|
|
839
|
-
user.email,
|
|
840
|
-
hashedPassword,
|
|
841
|
-
salt,
|
|
842
|
-
costCpu,
|
|
843
|
-
costMemory,
|
|
844
|
-
costParallel,
|
|
845
|
-
length,
|
|
846
|
-
user.name
|
|
847
|
-
)
|
|
848
|
-
);
|
|
849
|
-
break;
|
|
850
|
-
|
|
851
|
-
case "scryptmodified":
|
|
852
|
-
// Scrypt Modified (Firebase) requires salt, separator, and signer key
|
|
853
|
-
const modSalt =
|
|
854
|
-
typeof hashOptions.salt === "string" ? hashOptions.salt : "";
|
|
855
|
-
const saltSeparator =
|
|
856
|
-
typeof hashOptions.saltSeparator === "string"
|
|
857
|
-
? hashOptions.saltSeparator
|
|
858
|
-
: "";
|
|
859
|
-
const signerKey =
|
|
860
|
-
typeof hashOptions.signerKey === "string"
|
|
861
|
-
? hashOptions.signerKey
|
|
862
|
-
: "";
|
|
863
|
-
|
|
864
|
-
// Warn if critical parameters are missing
|
|
865
|
-
if (
|
|
866
|
-
!hashOptions.salt ||
|
|
867
|
-
!hashOptions.saltSeparator ||
|
|
868
|
-
!hashOptions.signerKey
|
|
869
|
-
) {
|
|
870
|
-
MessageFormatter.warning(
|
|
871
|
-
`User ${user.$id}: Missing critical Scrypt Modified parameters in hashOptions`,
|
|
872
|
-
{ prefix: "Transfer" }
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
|
|
876
|
-
await tryAwaitWithRetry(async () =>
|
|
877
|
-
remoteUsers.createScryptModifiedUser(
|
|
878
|
-
user.$id,
|
|
879
|
-
user.email,
|
|
880
|
-
hashedPassword,
|
|
881
|
-
modSalt,
|
|
882
|
-
saltSeparator,
|
|
883
|
-
signerKey,
|
|
884
|
-
user.name
|
|
885
|
-
)
|
|
886
|
-
);
|
|
887
|
-
break;
|
|
888
|
-
|
|
889
|
-
case "md5":
|
|
890
|
-
await tryAwaitWithRetry(async () =>
|
|
891
|
-
remoteUsers.createMD5User(
|
|
892
|
-
user.$id,
|
|
893
|
-
user.email,
|
|
894
|
-
hashedPassword,
|
|
895
|
-
user.name
|
|
896
|
-
)
|
|
897
|
-
);
|
|
898
|
-
break;
|
|
899
|
-
|
|
900
|
-
case "sha":
|
|
901
|
-
case "sha1":
|
|
902
|
-
case "sha256":
|
|
903
|
-
case "sha512":
|
|
904
|
-
// SHA variants - determine version from hash type
|
|
905
|
-
const getPasswordHashVersion = (hash: string) => {
|
|
906
|
-
switch (hash.toLowerCase()) {
|
|
907
|
-
case "sha1":
|
|
908
|
-
return "sha1" as any;
|
|
909
|
-
case "sha256":
|
|
910
|
-
return "sha256" as any;
|
|
911
|
-
case "sha512":
|
|
912
|
-
return "sha512" as any;
|
|
913
|
-
default:
|
|
914
|
-
return "sha256" as any; // Default to SHA256
|
|
915
|
-
}
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
await tryAwaitWithRetry(async () =>
|
|
919
|
-
remoteUsers.createSHAUser(
|
|
920
|
-
user.$id,
|
|
921
|
-
user.email,
|
|
922
|
-
hashedPassword,
|
|
923
|
-
getPasswordHashVersion(hashType),
|
|
924
|
-
user.name
|
|
925
|
-
)
|
|
926
|
-
);
|
|
927
|
-
break;
|
|
928
|
-
|
|
929
|
-
case "phpass":
|
|
930
|
-
await tryAwaitWithRetry(async () =>
|
|
931
|
-
remoteUsers.createPHPassUser(
|
|
932
|
-
user.$id,
|
|
933
|
-
user.email,
|
|
934
|
-
hashedPassword,
|
|
935
|
-
user.name
|
|
936
|
-
)
|
|
937
|
-
);
|
|
938
|
-
break;
|
|
939
|
-
|
|
940
|
-
default:
|
|
941
|
-
MessageFormatter.warning(
|
|
942
|
-
`Unknown hash type '${hashType}' for user ${user.$id}, falling back to Argon2`,
|
|
943
|
-
{ prefix: "Transfer" }
|
|
944
|
-
);
|
|
945
|
-
await tryAwaitWithRetry(async () =>
|
|
946
|
-
remoteUsers.createArgon2User(
|
|
947
|
-
user.$id,
|
|
948
|
-
user.email,
|
|
949
|
-
hashedPassword,
|
|
950
|
-
user.name
|
|
951
|
-
)
|
|
952
|
-
);
|
|
953
|
-
break;
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
MessageFormatter.success(
|
|
957
|
-
`User ${user.$id} created with preserved ${hashType} password`,
|
|
958
|
-
{ prefix: "Transfer" }
|
|
959
|
-
);
|
|
960
|
-
} catch (error) {
|
|
961
|
-
MessageFormatter.warning(
|
|
962
|
-
`Failed to create user ${user.$id} with ${hashType} hash, trying with temporary password`,
|
|
963
|
-
{ prefix: "Transfer" }
|
|
964
|
-
);
|
|
965
|
-
|
|
966
|
-
// Fallback to creating user with temporary password
|
|
967
|
-
await tryAwaitWithRetry(async () =>
|
|
968
|
-
remoteUsers.create(
|
|
969
|
-
user.$id,
|
|
970
|
-
user.email,
|
|
971
|
-
phone,
|
|
972
|
-
`changeMe${user.email}`,
|
|
973
|
-
user.name
|
|
974
|
-
)
|
|
975
|
-
);
|
|
976
|
-
|
|
977
|
-
MessageFormatter.warning(
|
|
978
|
-
`User ${user.$id} created with temporary password - password reset required`,
|
|
979
|
-
{ prefix: "Transfer" }
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
} else {
|
|
983
|
-
// No hash or password - create with temporary password
|
|
984
|
-
const tempPassword = user.password || `changeMe${user.email}`;
|
|
985
|
-
|
|
986
|
-
await tryAwaitWithRetry(async () =>
|
|
987
|
-
remoteUsers.create(
|
|
988
|
-
user.$id,
|
|
989
|
-
user.email,
|
|
990
|
-
phone,
|
|
991
|
-
tempPassword,
|
|
992
|
-
user.name
|
|
993
|
-
)
|
|
994
|
-
);
|
|
995
|
-
|
|
996
|
-
if (!user.password) {
|
|
997
|
-
MessageFormatter.warning(
|
|
998
|
-
`User ${user.$id} created with temporary password - password reset required`,
|
|
999
|
-
{ prefix: "Transfer" }
|
|
1000
|
-
);
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
// Update phone, labels, and other attributes for newly created users
|
|
1005
|
-
if (phone) {
|
|
1006
|
-
await tryAwaitWithRetry(async () =>
|
|
1007
|
-
remoteUsers.updatePhone(user.$id, phone)
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
|
|
1011
|
-
if (user.labels && user.labels.length > 0) {
|
|
1012
|
-
await tryAwaitWithRetry(async () =>
|
|
1013
|
-
remoteUsers.updateLabels(user.$id, user.labels)
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
|
|
1017
|
-
// Update user preferences and status for newly created users
|
|
1018
|
-
await tryAwaitWithRetry(async () =>
|
|
1019
|
-
remoteUsers.updatePrefs(user.$id, user.prefs)
|
|
1020
|
-
);
|
|
1021
|
-
|
|
1022
|
-
if (user.emailVerification) {
|
|
1023
|
-
await tryAwaitWithRetry(async () =>
|
|
1024
|
-
remoteUsers.updateEmailVerification(user.$id, true)
|
|
1025
|
-
);
|
|
1026
|
-
} else {
|
|
1027
|
-
await tryAwaitWithRetry(async () =>
|
|
1028
|
-
remoteUsers.updateEmailVerification(user.$id, false)
|
|
1029
|
-
);
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
if (user.phoneVerification) {
|
|
1033
|
-
await tryAwaitWithRetry(async () =>
|
|
1034
|
-
remoteUsers.updatePhoneVerification(user.$id, true)
|
|
1035
|
-
);
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
|
-
if (user.status === false) {
|
|
1039
|
-
await tryAwaitWithRetry(async () =>
|
|
1040
|
-
remoteUsers.updateStatus(user.$id, false)
|
|
1041
|
-
);
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
totalTransferred++;
|
|
1045
|
-
MessageFormatter.success(
|
|
1046
|
-
`Transferred user ${user.$id}`,
|
|
1047
|
-
{ prefix: "Transfer" }
|
|
1048
|
-
);
|
|
1049
|
-
} catch (error) {
|
|
1050
|
-
MessageFormatter.error(
|
|
1051
|
-
`Failed to transfer user ${user.$id}`,
|
|
1052
|
-
error instanceof Error ? error : new Error(String(error)),
|
|
1053
|
-
{ prefix: "Transfer" }
|
|
1054
|
-
);
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
if (usersList.users.length < 100) {
|
|
1059
|
-
break;
|
|
1060
|
-
}
|
|
1061
|
-
lastId = usersList.users[usersList.users.length - 1].$id;
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
MessageFormatter.success(
|
|
1065
|
-
`Successfully transferred ${totalTransferred} users`,
|
|
1066
|
-
{ prefix: "Transfer" }
|
|
1067
|
-
);
|
|
1068
|
-
};
|
|
622
|
+
|
|
623
|
+
// Transfer documents
|
|
624
|
+
const { transferDocumentsBetweenDbsLocalToRemote } = await import(
|
|
625
|
+
"../collections/methods.js"
|
|
626
|
+
);
|
|
627
|
+
await transferDocumentsBetweenDbsLocalToRemote(
|
|
628
|
+
localDb,
|
|
629
|
+
endpoint,
|
|
630
|
+
projectId,
|
|
631
|
+
apiKey,
|
|
632
|
+
fromDbId,
|
|
633
|
+
toDbId,
|
|
634
|
+
collection.$id,
|
|
635
|
+
targetCollection.$id
|
|
636
|
+
);
|
|
637
|
+
} catch (error) {
|
|
638
|
+
MessageFormatter.error(
|
|
639
|
+
`Error processing collection ${collection.name}`,
|
|
640
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
641
|
+
{ prefix: "Transfer" }
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
|
|
647
|
+
export const transferUsersLocalToRemote = async (
|
|
648
|
+
localUsers: Users,
|
|
649
|
+
endpoint: string,
|
|
650
|
+
projectId: string,
|
|
651
|
+
apiKey: string
|
|
652
|
+
) => {
|
|
653
|
+
MessageFormatter.info(
|
|
654
|
+
"Starting user transfer to remote instance...",
|
|
655
|
+
{ prefix: "Transfer" }
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
const client = getClient(endpoint, projectId, apiKey);
|
|
659
|
+
const remoteUsers = new Users(client);
|
|
660
|
+
|
|
661
|
+
let totalTransferred = 0;
|
|
662
|
+
let lastId: string | undefined;
|
|
663
|
+
|
|
664
|
+
while (true) {
|
|
665
|
+
const queries = [Query.limit(100)];
|
|
666
|
+
if (lastId) {
|
|
667
|
+
queries.push(Query.cursorAfter(lastId));
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
const usersList = await tryAwaitWithRetry(async () =>
|
|
671
|
+
localUsers.list(queries)
|
|
672
|
+
);
|
|
673
|
+
|
|
674
|
+
if (usersList.users.length === 0) {
|
|
675
|
+
break;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
for (const user of usersList.users) {
|
|
679
|
+
try {
|
|
680
|
+
// Check if user already exists in remote
|
|
681
|
+
let remoteUser: Models.User<Models.Preferences> | undefined;
|
|
682
|
+
try {
|
|
683
|
+
remoteUser = await tryAwaitWithRetry(async () =>
|
|
684
|
+
remoteUsers.get(user.$id)
|
|
685
|
+
);
|
|
686
|
+
|
|
687
|
+
// If user exists, update only the differences
|
|
688
|
+
if (remoteUser) {
|
|
689
|
+
MessageFormatter.info(
|
|
690
|
+
`User ${user.$id} exists, checking for updates...`,
|
|
691
|
+
{ prefix: "Transfer" }
|
|
692
|
+
);
|
|
693
|
+
let hasUpdates = false;
|
|
694
|
+
|
|
695
|
+
// Update name if different
|
|
696
|
+
if (remoteUser.name !== user.name) {
|
|
697
|
+
await tryAwaitWithRetry(async () =>
|
|
698
|
+
remoteUsers.updateName(user.$id, user.name)
|
|
699
|
+
);
|
|
700
|
+
MessageFormatter.success(
|
|
701
|
+
`Updated name for user ${user.$id}`,
|
|
702
|
+
{ prefix: "Transfer" }
|
|
703
|
+
);
|
|
704
|
+
hasUpdates = true;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// Update email if different
|
|
708
|
+
if (remoteUser.email !== user.email) {
|
|
709
|
+
await tryAwaitWithRetry(async () =>
|
|
710
|
+
remoteUsers.updateEmail(user.$id, user.email)
|
|
711
|
+
);
|
|
712
|
+
MessageFormatter.success(
|
|
713
|
+
`Updated email for user ${user.$id}`,
|
|
714
|
+
{ prefix: "Transfer" }
|
|
715
|
+
);
|
|
716
|
+
hasUpdates = true;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// Update phone if different
|
|
720
|
+
const normalizedLocalPhone = user.phone
|
|
721
|
+
? converterFunctions.convertPhoneStringToUSInternational(user.phone)
|
|
722
|
+
: undefined;
|
|
723
|
+
if (remoteUser.phone !== normalizedLocalPhone) {
|
|
724
|
+
if (normalizedLocalPhone) {
|
|
725
|
+
await tryAwaitWithRetry(async () =>
|
|
726
|
+
remoteUsers.updatePhone(user.$id, normalizedLocalPhone)
|
|
727
|
+
);
|
|
728
|
+
}
|
|
729
|
+
MessageFormatter.success(
|
|
730
|
+
`Updated phone for user ${user.$id}`,
|
|
731
|
+
{ prefix: "Transfer" }
|
|
732
|
+
);
|
|
733
|
+
hasUpdates = true;
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// Update preferences if different
|
|
737
|
+
if (JSON.stringify(remoteUser.prefs) !== JSON.stringify(user.prefs)) {
|
|
738
|
+
await tryAwaitWithRetry(async () =>
|
|
739
|
+
remoteUsers.updatePrefs(user.$id, user.prefs)
|
|
740
|
+
);
|
|
741
|
+
MessageFormatter.success(
|
|
742
|
+
`Updated preferences for user ${user.$id}`,
|
|
743
|
+
{ prefix: "Transfer" }
|
|
744
|
+
);
|
|
745
|
+
hasUpdates = true;
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// Update labels if different
|
|
749
|
+
if (JSON.stringify(remoteUser.labels) !== JSON.stringify(user.labels)) {
|
|
750
|
+
await tryAwaitWithRetry(async () =>
|
|
751
|
+
remoteUsers.updateLabels(user.$id, user.labels)
|
|
752
|
+
);
|
|
753
|
+
MessageFormatter.success(
|
|
754
|
+
`Updated labels for user ${user.$id}`,
|
|
755
|
+
{ prefix: "Transfer" }
|
|
756
|
+
);
|
|
757
|
+
hasUpdates = true;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// Update email verification if different
|
|
761
|
+
if (remoteUser.emailVerification !== user.emailVerification) {
|
|
762
|
+
await tryAwaitWithRetry(async () =>
|
|
763
|
+
remoteUsers.updateEmailVerification(user.$id, user.emailVerification)
|
|
764
|
+
);
|
|
765
|
+
MessageFormatter.success(
|
|
766
|
+
`Updated email verification for user ${user.$id}`,
|
|
767
|
+
{ prefix: "Transfer" }
|
|
768
|
+
);
|
|
769
|
+
hasUpdates = true;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// Update phone verification if different
|
|
773
|
+
if (remoteUser.phoneVerification !== user.phoneVerification) {
|
|
774
|
+
await tryAwaitWithRetry(async () =>
|
|
775
|
+
remoteUsers.updatePhoneVerification(user.$id, user.phoneVerification)
|
|
776
|
+
);
|
|
777
|
+
MessageFormatter.success(
|
|
778
|
+
`Updated phone verification for user ${user.$id}`,
|
|
779
|
+
{ prefix: "Transfer" }
|
|
780
|
+
);
|
|
781
|
+
hasUpdates = true;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
// Update status if different
|
|
785
|
+
if (remoteUser.status !== user.status) {
|
|
786
|
+
await tryAwaitWithRetry(async () =>
|
|
787
|
+
remoteUsers.updateStatus(user.$id, user.status)
|
|
788
|
+
);
|
|
789
|
+
MessageFormatter.success(
|
|
790
|
+
`Updated status for user ${user.$id}`,
|
|
791
|
+
{ prefix: "Transfer" }
|
|
792
|
+
);
|
|
793
|
+
hasUpdates = true;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
if (!hasUpdates) {
|
|
797
|
+
MessageFormatter.info(
|
|
798
|
+
`User ${user.$id} is already up to date, skipping...`,
|
|
799
|
+
{ prefix: "Transfer" }
|
|
800
|
+
);
|
|
801
|
+
} else {
|
|
802
|
+
totalTransferred++;
|
|
803
|
+
MessageFormatter.success(
|
|
804
|
+
`Updated user ${user.$id}`,
|
|
805
|
+
{ prefix: "Transfer" }
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
continue;
|
|
809
|
+
}
|
|
810
|
+
} catch (error: any) {
|
|
811
|
+
// User doesn't exist, proceed with creation
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
const phone = user.phone
|
|
815
|
+
? converterFunctions.convertPhoneStringToUSInternational(user.phone)
|
|
816
|
+
: undefined;
|
|
817
|
+
|
|
818
|
+
// Handle user creation based on hash type
|
|
819
|
+
if (user.hash && user.password) {
|
|
820
|
+
// User has a hashed password - recreate with proper hash method
|
|
821
|
+
const hashType = user.hash.toLowerCase();
|
|
822
|
+
const hashedPassword = user.password; // This is already hashed
|
|
823
|
+
const hashOptions = (user.hashOptions as Record<string, any>) || {};
|
|
824
|
+
|
|
825
|
+
try {
|
|
826
|
+
switch (hashType) {
|
|
827
|
+
case "argon2":
|
|
828
|
+
await tryAwaitWithRetry(async () =>
|
|
829
|
+
remoteUsers.createArgon2User(
|
|
830
|
+
user.$id,
|
|
831
|
+
user.email,
|
|
832
|
+
hashedPassword,
|
|
833
|
+
user.name
|
|
834
|
+
)
|
|
835
|
+
);
|
|
836
|
+
break;
|
|
837
|
+
|
|
838
|
+
case "bcrypt":
|
|
839
|
+
await tryAwaitWithRetry(async () =>
|
|
840
|
+
remoteUsers.createBcryptUser(
|
|
841
|
+
user.$id,
|
|
842
|
+
user.email,
|
|
843
|
+
hashedPassword,
|
|
844
|
+
user.name
|
|
845
|
+
)
|
|
846
|
+
);
|
|
847
|
+
break;
|
|
848
|
+
|
|
849
|
+
case "scrypt":
|
|
850
|
+
// Scrypt requires additional parameters from hashOptions
|
|
851
|
+
const salt =
|
|
852
|
+
typeof hashOptions.salt === "string" ? hashOptions.salt : "";
|
|
853
|
+
const costCpu =
|
|
854
|
+
typeof hashOptions.costCpu === "number"
|
|
855
|
+
? hashOptions.costCpu
|
|
856
|
+
: 32768;
|
|
857
|
+
const costMemory =
|
|
858
|
+
typeof hashOptions.costMemory === "number"
|
|
859
|
+
? hashOptions.costMemory
|
|
860
|
+
: 14;
|
|
861
|
+
const costParallel =
|
|
862
|
+
typeof hashOptions.costParallel === "number"
|
|
863
|
+
? hashOptions.costParallel
|
|
864
|
+
: 1;
|
|
865
|
+
const length =
|
|
866
|
+
typeof hashOptions.length === "number"
|
|
867
|
+
? hashOptions.length
|
|
868
|
+
: 64;
|
|
869
|
+
|
|
870
|
+
// Warn if using default values due to missing hash options
|
|
871
|
+
if (
|
|
872
|
+
!hashOptions.salt ||
|
|
873
|
+
typeof hashOptions.costCpu !== "number"
|
|
874
|
+
) {
|
|
875
|
+
MessageFormatter.warning(
|
|
876
|
+
`User ${user.$id}: Using default Scrypt parameters due to missing hashOptions`,
|
|
877
|
+
{ prefix: "Transfer" }
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
await tryAwaitWithRetry(async () =>
|
|
882
|
+
remoteUsers.createScryptUser(
|
|
883
|
+
user.$id,
|
|
884
|
+
user.email,
|
|
885
|
+
hashedPassword,
|
|
886
|
+
salt,
|
|
887
|
+
costCpu,
|
|
888
|
+
costMemory,
|
|
889
|
+
costParallel,
|
|
890
|
+
length,
|
|
891
|
+
user.name
|
|
892
|
+
)
|
|
893
|
+
);
|
|
894
|
+
break;
|
|
895
|
+
|
|
896
|
+
case "scryptmodified":
|
|
897
|
+
// Scrypt Modified (Firebase) requires salt, separator, and signer key
|
|
898
|
+
const modSalt =
|
|
899
|
+
typeof hashOptions.salt === "string" ? hashOptions.salt : "";
|
|
900
|
+
const saltSeparator =
|
|
901
|
+
typeof hashOptions.saltSeparator === "string"
|
|
902
|
+
? hashOptions.saltSeparator
|
|
903
|
+
: "";
|
|
904
|
+
const signerKey =
|
|
905
|
+
typeof hashOptions.signerKey === "string"
|
|
906
|
+
? hashOptions.signerKey
|
|
907
|
+
: "";
|
|
908
|
+
|
|
909
|
+
// Warn if critical parameters are missing
|
|
910
|
+
if (
|
|
911
|
+
!hashOptions.salt ||
|
|
912
|
+
!hashOptions.saltSeparator ||
|
|
913
|
+
!hashOptions.signerKey
|
|
914
|
+
) {
|
|
915
|
+
MessageFormatter.warning(
|
|
916
|
+
`User ${user.$id}: Missing critical Scrypt Modified parameters in hashOptions`,
|
|
917
|
+
{ prefix: "Transfer" }
|
|
918
|
+
);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
await tryAwaitWithRetry(async () =>
|
|
922
|
+
remoteUsers.createScryptModifiedUser(
|
|
923
|
+
user.$id,
|
|
924
|
+
user.email,
|
|
925
|
+
hashedPassword,
|
|
926
|
+
modSalt,
|
|
927
|
+
saltSeparator,
|
|
928
|
+
signerKey,
|
|
929
|
+
user.name
|
|
930
|
+
)
|
|
931
|
+
);
|
|
932
|
+
break;
|
|
933
|
+
|
|
934
|
+
case "md5":
|
|
935
|
+
await tryAwaitWithRetry(async () =>
|
|
936
|
+
remoteUsers.createMD5User(
|
|
937
|
+
user.$id,
|
|
938
|
+
user.email,
|
|
939
|
+
hashedPassword,
|
|
940
|
+
user.name
|
|
941
|
+
)
|
|
942
|
+
);
|
|
943
|
+
break;
|
|
944
|
+
|
|
945
|
+
case "sha":
|
|
946
|
+
case "sha1":
|
|
947
|
+
case "sha256":
|
|
948
|
+
case "sha512":
|
|
949
|
+
// SHA variants - determine version from hash type
|
|
950
|
+
const getPasswordHashVersion = (hash: string) => {
|
|
951
|
+
switch (hash.toLowerCase()) {
|
|
952
|
+
case "sha1":
|
|
953
|
+
return "sha1" as any;
|
|
954
|
+
case "sha256":
|
|
955
|
+
return "sha256" as any;
|
|
956
|
+
case "sha512":
|
|
957
|
+
return "sha512" as any;
|
|
958
|
+
default:
|
|
959
|
+
return "sha256" as any; // Default to SHA256
|
|
960
|
+
}
|
|
961
|
+
};
|
|
962
|
+
|
|
963
|
+
await tryAwaitWithRetry(async () =>
|
|
964
|
+
remoteUsers.createSHAUser(
|
|
965
|
+
user.$id,
|
|
966
|
+
user.email,
|
|
967
|
+
hashedPassword,
|
|
968
|
+
getPasswordHashVersion(hashType),
|
|
969
|
+
user.name
|
|
970
|
+
)
|
|
971
|
+
);
|
|
972
|
+
break;
|
|
973
|
+
|
|
974
|
+
case "phpass":
|
|
975
|
+
await tryAwaitWithRetry(async () =>
|
|
976
|
+
remoteUsers.createPHPassUser(
|
|
977
|
+
user.$id,
|
|
978
|
+
user.email,
|
|
979
|
+
hashedPassword,
|
|
980
|
+
user.name
|
|
981
|
+
)
|
|
982
|
+
);
|
|
983
|
+
break;
|
|
984
|
+
|
|
985
|
+
default:
|
|
986
|
+
MessageFormatter.warning(
|
|
987
|
+
`Unknown hash type '${hashType}' for user ${user.$id}, falling back to Argon2`,
|
|
988
|
+
{ prefix: "Transfer" }
|
|
989
|
+
);
|
|
990
|
+
await tryAwaitWithRetry(async () =>
|
|
991
|
+
remoteUsers.createArgon2User(
|
|
992
|
+
user.$id,
|
|
993
|
+
user.email,
|
|
994
|
+
hashedPassword,
|
|
995
|
+
user.name
|
|
996
|
+
)
|
|
997
|
+
);
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
MessageFormatter.success(
|
|
1002
|
+
`User ${user.$id} created with preserved ${hashType} password`,
|
|
1003
|
+
{ prefix: "Transfer" }
|
|
1004
|
+
);
|
|
1005
|
+
} catch (error) {
|
|
1006
|
+
MessageFormatter.warning(
|
|
1007
|
+
`Failed to create user ${user.$id} with ${hashType} hash, trying with temporary password`,
|
|
1008
|
+
{ prefix: "Transfer" }
|
|
1009
|
+
);
|
|
1010
|
+
|
|
1011
|
+
// Fallback to creating user with temporary password
|
|
1012
|
+
await tryAwaitWithRetry(async () =>
|
|
1013
|
+
remoteUsers.create(
|
|
1014
|
+
user.$id,
|
|
1015
|
+
user.email,
|
|
1016
|
+
phone,
|
|
1017
|
+
`changeMe${user.email}`,
|
|
1018
|
+
user.name
|
|
1019
|
+
)
|
|
1020
|
+
);
|
|
1021
|
+
|
|
1022
|
+
MessageFormatter.warning(
|
|
1023
|
+
`User ${user.$id} created with temporary password - password reset required`,
|
|
1024
|
+
{ prefix: "Transfer" }
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
} else {
|
|
1028
|
+
// No hash or password - create with temporary password
|
|
1029
|
+
const tempPassword = user.password || `changeMe${user.email}`;
|
|
1030
|
+
|
|
1031
|
+
await tryAwaitWithRetry(async () =>
|
|
1032
|
+
remoteUsers.create(
|
|
1033
|
+
user.$id,
|
|
1034
|
+
user.email,
|
|
1035
|
+
phone,
|
|
1036
|
+
tempPassword,
|
|
1037
|
+
user.name
|
|
1038
|
+
)
|
|
1039
|
+
);
|
|
1040
|
+
|
|
1041
|
+
if (!user.password) {
|
|
1042
|
+
MessageFormatter.warning(
|
|
1043
|
+
`User ${user.$id} created with temporary password - password reset required`,
|
|
1044
|
+
{ prefix: "Transfer" }
|
|
1045
|
+
);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
// Update phone, labels, and other attributes for newly created users
|
|
1050
|
+
if (phone) {
|
|
1051
|
+
await tryAwaitWithRetry(async () =>
|
|
1052
|
+
remoteUsers.updatePhone(user.$id, phone)
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
if (user.labels && user.labels.length > 0) {
|
|
1057
|
+
await tryAwaitWithRetry(async () =>
|
|
1058
|
+
remoteUsers.updateLabels(user.$id, user.labels)
|
|
1059
|
+
);
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
// Update user preferences and status for newly created users
|
|
1063
|
+
await tryAwaitWithRetry(async () =>
|
|
1064
|
+
remoteUsers.updatePrefs(user.$id, user.prefs)
|
|
1065
|
+
);
|
|
1066
|
+
|
|
1067
|
+
if (user.emailVerification) {
|
|
1068
|
+
await tryAwaitWithRetry(async () =>
|
|
1069
|
+
remoteUsers.updateEmailVerification(user.$id, true)
|
|
1070
|
+
);
|
|
1071
|
+
} else {
|
|
1072
|
+
await tryAwaitWithRetry(async () =>
|
|
1073
|
+
remoteUsers.updateEmailVerification(user.$id, false)
|
|
1074
|
+
);
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
if (user.phoneVerification) {
|
|
1078
|
+
await tryAwaitWithRetry(async () =>
|
|
1079
|
+
remoteUsers.updatePhoneVerification(user.$id, true)
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
if (user.status === false) {
|
|
1084
|
+
await tryAwaitWithRetry(async () =>
|
|
1085
|
+
remoteUsers.updateStatus(user.$id, false)
|
|
1086
|
+
);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
totalTransferred++;
|
|
1090
|
+
MessageFormatter.success(
|
|
1091
|
+
`Transferred user ${user.$id}`,
|
|
1092
|
+
{ prefix: "Transfer" }
|
|
1093
|
+
);
|
|
1094
|
+
} catch (error) {
|
|
1095
|
+
MessageFormatter.error(
|
|
1096
|
+
`Failed to transfer user ${user.$id}`,
|
|
1097
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
1098
|
+
{ prefix: "Transfer" }
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
if (usersList.users.length < 100) {
|
|
1104
|
+
break;
|
|
1105
|
+
}
|
|
1106
|
+
lastId = usersList.users[usersList.users.length - 1].$id;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
MessageFormatter.success(
|
|
1110
|
+
`Successfully transferred ${totalTransferred} users`,
|
|
1111
|
+
{ prefix: "Transfer" }
|
|
1112
|
+
);
|
|
1113
|
+
};
|