appbuild-oceanbase-console 1.11.1 → 1.12.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/dist/cjs/sdk.js +106 -17
- package/dist/cjs/sdk.js.map +1 -1
- package/dist/esm/sdk.js +106 -18
- package/dist/esm/sdk.js.map +1 -1
- package/dist/iife/sdk.js +106 -17
- package/package.json +1 -1
- package/types/client.d.ts +5 -1
- package/types/index.d.ts +2 -2
- package/types/migrations.d.ts +32 -0
package/dist/cjs/sdk.js
CHANGED
|
@@ -434,9 +434,9 @@ Query.notTouches = (attribute, values) => new Query("notTouches", attribute, [va
|
|
|
434
434
|
/**
|
|
435
435
|
* Environment detection helpers
|
|
436
436
|
*/
|
|
437
|
-
const isBrowser = typeof window !== 'undefined';
|
|
437
|
+
const isBrowser$1 = typeof window !== 'undefined';
|
|
438
438
|
// Memory storage for server-side environment
|
|
439
|
-
class MemoryStorage {
|
|
439
|
+
class MemoryStorage$1 {
|
|
440
440
|
constructor() {
|
|
441
441
|
this.data = new Map();
|
|
442
442
|
}
|
|
@@ -450,9 +450,9 @@ class MemoryStorage {
|
|
|
450
450
|
this.data.delete(key);
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
const memoryStorage = new MemoryStorage();
|
|
454
|
-
const getStorage = () => isBrowser ? window.localStorage : memoryStorage;
|
|
455
|
-
const getLocation = () => isBrowser ? window.location : { host: 'nodejs' };
|
|
453
|
+
const memoryStorage$1 = new MemoryStorage$1();
|
|
454
|
+
const getStorage$1 = () => isBrowser$1 ? window.localStorage : memoryStorage$1;
|
|
455
|
+
const getLocation = () => isBrowser$1 ? window.location : { host: 'nodejs' };
|
|
456
456
|
const getWebSocket = () => {
|
|
457
457
|
if (typeof WebSocket !== 'undefined')
|
|
458
458
|
return WebSocket;
|
|
@@ -619,7 +619,7 @@ class Client {
|
|
|
619
619
|
case 'connected':
|
|
620
620
|
let session = this.config.session;
|
|
621
621
|
if (!session) {
|
|
622
|
-
const storage = getStorage();
|
|
622
|
+
const storage = getStorage$1();
|
|
623
623
|
const cookieFallback = storage.getItem('cookieFallback');
|
|
624
624
|
if (cookieFallback) {
|
|
625
625
|
const cookie = JSON.parse(cookieFallback);
|
|
@@ -772,6 +772,19 @@ class Client {
|
|
|
772
772
|
this.config.mode = value;
|
|
773
773
|
return this;
|
|
774
774
|
}
|
|
775
|
+
/**
|
|
776
|
+
* Set Session Refresh Handler
|
|
777
|
+
*
|
|
778
|
+
* Set a callback function that will be called when a 401 error is detected.
|
|
779
|
+
* This allows automatic re-login when session expires.
|
|
780
|
+
*
|
|
781
|
+
* @param handler Function that returns a Promise to refresh the session
|
|
782
|
+
* @returns {this}
|
|
783
|
+
*/
|
|
784
|
+
setSessionRefreshHandler(handler) {
|
|
785
|
+
this.sessionRefreshHandler = handler;
|
|
786
|
+
return this;
|
|
787
|
+
}
|
|
775
788
|
/**
|
|
776
789
|
* Subscribes to Appwrite events and passes you the payload in realtime.
|
|
777
790
|
*
|
|
@@ -818,7 +831,7 @@ class Client {
|
|
|
818
831
|
prepareRequest(method, url, headers = {}, params = {}) {
|
|
819
832
|
method = method.toUpperCase();
|
|
820
833
|
headers = Object.assign({}, this.headers, headers);
|
|
821
|
-
const storage = getStorage();
|
|
834
|
+
const storage = getStorage$1();
|
|
822
835
|
const cookieFallback = storage.getItem('cookieFallback');
|
|
823
836
|
if (cookieFallback) {
|
|
824
837
|
headers['X-Fallback-Cookies'] = cookieFallback;
|
|
@@ -906,7 +919,7 @@ class Client {
|
|
|
906
919
|
return this.call('GET', new URL(this.config.endpoint + '/ping'));
|
|
907
920
|
});
|
|
908
921
|
}
|
|
909
|
-
call(method, url, headers = {}, params = {}, responseType = 'json') {
|
|
922
|
+
call(method, url, headers = {}, params = {}, responseType = 'json', retryOn401 = true) {
|
|
910
923
|
var _a, _b;
|
|
911
924
|
return __awaiter(this, void 0, void 0, function* () {
|
|
912
925
|
const { uri, options } = this.prepareRequest(method, url, headers, params);
|
|
@@ -950,6 +963,17 @@ class Client {
|
|
|
950
963
|
};
|
|
951
964
|
}
|
|
952
965
|
if (400 <= response.status) {
|
|
966
|
+
// Handle 401 Unauthorized with automatic re-login
|
|
967
|
+
if (response.status === 401 && retryOn401 && this.sessionRefreshHandler) {
|
|
968
|
+
try {
|
|
969
|
+
yield this.sessionRefreshHandler();
|
|
970
|
+
// Retry the request once after re-login
|
|
971
|
+
return this.call(method, url, headers, params, responseType, false);
|
|
972
|
+
}
|
|
973
|
+
catch (refreshError) {
|
|
974
|
+
// If refresh fails, throw the original 401 error
|
|
975
|
+
}
|
|
976
|
+
}
|
|
953
977
|
let responseText = '';
|
|
954
978
|
if (((_b = response.headers.get('content-type')) === null || _b === void 0 ? void 0 : _b.includes('application/json')) || responseType === 'arrayBuffer') {
|
|
955
979
|
responseText = JSON.stringify(data);
|
|
@@ -961,9 +985,9 @@ class Client {
|
|
|
961
985
|
}
|
|
962
986
|
const cookieFallback = response.headers.get('X-Fallback-Cookies');
|
|
963
987
|
if (cookieFallback) {
|
|
964
|
-
const storage = getStorage();
|
|
988
|
+
const storage = getStorage$1();
|
|
965
989
|
storage.setItem('cookieFallback', cookieFallback);
|
|
966
|
-
if (isBrowser) {
|
|
990
|
+
if (isBrowser$1) {
|
|
967
991
|
console.warn('Appwrite is using localStorage for session management. Increase your security by adding a custom domain as your API endpoint.');
|
|
968
992
|
}
|
|
969
993
|
}
|
|
@@ -13943,6 +13967,26 @@ class Role {
|
|
|
13943
13967
|
}
|
|
13944
13968
|
}
|
|
13945
13969
|
|
|
13970
|
+
/**
|
|
13971
|
+
* Exception thrown when migration execution fails
|
|
13972
|
+
* Contains information about all failed operations
|
|
13973
|
+
*/
|
|
13974
|
+
class MigrationExecutionException extends Error {
|
|
13975
|
+
constructor(failedOperations, totalOperations) {
|
|
13976
|
+
const failedCount = failedOperations.length;
|
|
13977
|
+
const succeededCount = totalOperations - failedCount;
|
|
13978
|
+
const errorMessages = failedOperations.map(fo => ` - ${fo.operation.type} for collection ${fo.operation.collectionId}: ${fo.errorMessage}`).join('\n');
|
|
13979
|
+
const message = `Migration execution completed with ${failedCount} failure(s) out of ${totalOperations} operation(s).\n` +
|
|
13980
|
+
`Succeeded: ${succeededCount}, Failed: ${failedCount}\n\n` +
|
|
13981
|
+
`Failed operations:\n${errorMessages}`;
|
|
13982
|
+
super(message);
|
|
13983
|
+
this.name = 'MigrationExecutionException';
|
|
13984
|
+
this.failedOperations = failedOperations;
|
|
13985
|
+
this.totalOperations = totalOperations;
|
|
13986
|
+
this.succeededOperations = succeededCount;
|
|
13987
|
+
this.failedOperationsCount = failedCount;
|
|
13988
|
+
}
|
|
13989
|
+
}
|
|
13946
13990
|
/**
|
|
13947
13991
|
* Database Schema Migration Tool
|
|
13948
13992
|
*
|
|
@@ -14434,18 +14478,37 @@ class SchemaMigration {
|
|
|
14434
14478
|
}
|
|
14435
14479
|
// Store schema for use in executeOperation
|
|
14436
14480
|
this._currentSchema = schema;
|
|
14437
|
-
// Execute operations in order
|
|
14481
|
+
// Execute operations in order and collect all failures
|
|
14482
|
+
const failedOperations = [];
|
|
14438
14483
|
for (const operation of plan.operations) {
|
|
14439
14484
|
try {
|
|
14440
14485
|
yield this.executeOperation(operation);
|
|
14441
14486
|
}
|
|
14442
14487
|
catch (error) {
|
|
14443
14488
|
if (error instanceof AppwriteException) {
|
|
14444
|
-
|
|
14489
|
+
// Collect the error instead of throwing immediately
|
|
14490
|
+
const errorMessage = `Failed to execute ${operation.type} for collection ${operation.collectionId}: ${error.message}`;
|
|
14491
|
+
failedOperations.push({
|
|
14492
|
+
operation,
|
|
14493
|
+
error,
|
|
14494
|
+
errorMessage
|
|
14495
|
+
});
|
|
14496
|
+
}
|
|
14497
|
+
else {
|
|
14498
|
+
// For non-AppwriteException errors, still collect but mark as unexpected
|
|
14499
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
14500
|
+
failedOperations.push({
|
|
14501
|
+
operation,
|
|
14502
|
+
error: new AppwriteException(`Unexpected error: ${errorMessage}`, 500, 'unexpected_error', JSON.stringify(error)),
|
|
14503
|
+
errorMessage: `Unexpected error during ${operation.type} for collection ${operation.collectionId}: ${errorMessage}`
|
|
14504
|
+
});
|
|
14445
14505
|
}
|
|
14446
|
-
throw error;
|
|
14447
14506
|
}
|
|
14448
14507
|
}
|
|
14508
|
+
// If there were any failures, throw an exception with all failure details
|
|
14509
|
+
if (failedOperations.length > 0) {
|
|
14510
|
+
throw new MigrationExecutionException(failedOperations, plan.operations.length);
|
|
14511
|
+
}
|
|
14449
14512
|
});
|
|
14450
14513
|
}
|
|
14451
14514
|
/**
|
|
@@ -25625,6 +25688,27 @@ class Vcs {
|
|
|
25625
25688
|
}
|
|
25626
25689
|
}
|
|
25627
25690
|
|
|
25691
|
+
/**
|
|
25692
|
+
* Environment detection helper
|
|
25693
|
+
*/
|
|
25694
|
+
const isBrowser = typeof window !== 'undefined';
|
|
25695
|
+
// Memory storage for server-side environment
|
|
25696
|
+
class MemoryStorage {
|
|
25697
|
+
constructor() {
|
|
25698
|
+
this.data = new Map();
|
|
25699
|
+
}
|
|
25700
|
+
getItem(key) {
|
|
25701
|
+
return this.data.get(key) || null;
|
|
25702
|
+
}
|
|
25703
|
+
setItem(key, value) {
|
|
25704
|
+
this.data.set(key, value);
|
|
25705
|
+
}
|
|
25706
|
+
removeItem(key) {
|
|
25707
|
+
this.data.delete(key);
|
|
25708
|
+
}
|
|
25709
|
+
}
|
|
25710
|
+
const memoryStorage = new MemoryStorage();
|
|
25711
|
+
const getStorage = () => isBrowser ? window.localStorage : memoryStorage;
|
|
25628
25712
|
var RealtimeCode;
|
|
25629
25713
|
(function (RealtimeCode) {
|
|
25630
25714
|
RealtimeCode[RealtimeCode["NORMAL_CLOSURE"] = 1000] = "NORMAL_CLOSURE";
|
|
@@ -25866,7 +25950,7 @@ class Realtime {
|
|
|
25866
25950
|
}
|
|
25867
25951
|
}
|
|
25868
25952
|
handleResponseConnected(message) {
|
|
25869
|
-
var _a
|
|
25953
|
+
var _a;
|
|
25870
25954
|
if (!message.data) {
|
|
25871
25955
|
return;
|
|
25872
25956
|
}
|
|
@@ -25874,15 +25958,19 @@ class Realtime {
|
|
|
25874
25958
|
let session = this.client.config.session;
|
|
25875
25959
|
if (!session) {
|
|
25876
25960
|
try {
|
|
25877
|
-
const
|
|
25878
|
-
|
|
25961
|
+
const storage = getStorage();
|
|
25962
|
+
const cookieFallback = storage.getItem('cookieFallback');
|
|
25963
|
+
if (cookieFallback) {
|
|
25964
|
+
const cookie = JSON.parse(cookieFallback);
|
|
25965
|
+
session = cookie === null || cookie === void 0 ? void 0 : cookie[`a_session_${this.client.config.project}`];
|
|
25966
|
+
}
|
|
25879
25967
|
}
|
|
25880
25968
|
catch (error) {
|
|
25881
25969
|
console.error('Failed to parse cookie fallback:', error);
|
|
25882
25970
|
}
|
|
25883
25971
|
}
|
|
25884
25972
|
if (session && !messageData.user) {
|
|
25885
|
-
(
|
|
25973
|
+
(_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify({
|
|
25886
25974
|
type: 'authentication',
|
|
25887
25975
|
data: {
|
|
25888
25976
|
session
|
|
@@ -27877,6 +27965,7 @@ exports.Health = Health;
|
|
|
27877
27965
|
exports.ID = ID;
|
|
27878
27966
|
exports.Locale = Locale;
|
|
27879
27967
|
exports.Messaging = Messaging;
|
|
27968
|
+
exports.MigrationExecutionException = MigrationExecutionException;
|
|
27880
27969
|
exports.Migrations = Migrations;
|
|
27881
27970
|
exports.Operator = Operator;
|
|
27882
27971
|
exports.Organizations = Organizations;
|