wabe 0.5.21 → 0.5.22

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/index.d.ts CHANGED
@@ -409,7 +409,7 @@ export declare const buildMongoWhereQuery: <T extends WabeTypes, K extends keyof
409
409
  export declare class MongoAdapter<T extends WabeTypes> implements DatabaseAdapter<T> {
410
410
  options: AdapterOptions;
411
411
  database?: Db;
412
- private client;
412
+ client: MongoClient;
413
413
  constructor(options: AdapterOptions);
414
414
  connect(): Promise<MongoClient>;
415
415
  close(): Promise<void>;
@@ -893,12 +893,6 @@ export type AuthenticationEventsOptionsWithUserId<T> = AuthenticationEventsOptio
893
893
  export type ProviderInterface<T = any> = {
894
894
  onSignIn: (options: AuthenticationEventsOptions<T>) => Promise<{
895
895
  user: Partial<User>;
896
- oauth?: {
897
- refreshToken: string;
898
- accessToken: string;
899
- accessTokenExpiresAt: Date;
900
- refreshTokenExpiresAt: Date;
901
- };
902
896
  }>;
903
897
  onSignUp: (options: AuthenticationEventsOptions<T>) => Promise<{
904
898
  authenticationDataToSave: any;
@@ -1277,6 +1271,15 @@ declare class PaymentController implements PaymentAdapter {
1277
1271
  getAllTransactions(options: GetAllTransactionsOptions): Promise<Transaction[]>;
1278
1272
  getHypotheticalSubscriptionRevenue(): Promise<number>;
1279
1273
  }
1274
+ export interface CreateCompletionOptions {
1275
+ content: string;
1276
+ }
1277
+ export interface AIAdapter {
1278
+ createCompletion(options: CreateCompletionOptions): Promise<string>;
1279
+ }
1280
+ export interface AIConfig {
1281
+ adapter: AIAdapter;
1282
+ }
1280
1283
  export type SecurityConfig = {
1281
1284
  corsOptions?: CorsOptions;
1282
1285
  rateLimit?: RateLimitOptions;
@@ -1299,6 +1302,7 @@ export interface WabeConfig<T extends WabeTypes> {
1299
1302
  hooks?: Hook<T, any>[];
1300
1303
  email?: EmailConfig;
1301
1304
  payment?: PaymentConfig;
1305
+ ai?: AIConfig;
1302
1306
  file?: FileConfig;
1303
1307
  }
1304
1308
  export type WabeTypes = {
@@ -1431,6 +1435,7 @@ export declare class PaymentDevAdapter implements PaymentAdapter {
1431
1435
  getAllTransactions(): Promise<never[]>;
1432
1436
  getHypotheticalSubscriptionRevenue(): Promise<number>;
1433
1437
  }
1438
+ export declare const contextWithRoot: (context: WabeContext<any>) => WabeContext<any>;
1434
1439
 
1435
1440
  export {
1436
1441
  AuthenticationProvider$1 as AuthenticationProvider,
package/dist/index.js CHANGED
@@ -43364,6 +43364,223 @@ var require_lib5 = __commonJS((exports) => {
43364
43364
  } });
43365
43365
  });
43366
43366
 
43367
+ // ../../node_modules/retry/lib/retry_operation.js
43368
+ var require_retry_operation = __commonJS((exports, module) => {
43369
+ function RetryOperation(timeouts, options) {
43370
+ if (typeof options === "boolean") {
43371
+ options = { forever: options };
43372
+ }
43373
+ this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
43374
+ this._timeouts = timeouts;
43375
+ this._options = options || {};
43376
+ this._maxRetryTime = options && options.maxRetryTime || Infinity;
43377
+ this._fn = null;
43378
+ this._errors = [];
43379
+ this._attempts = 1;
43380
+ this._operationTimeout = null;
43381
+ this._operationTimeoutCb = null;
43382
+ this._timeout = null;
43383
+ this._operationStart = null;
43384
+ this._timer = null;
43385
+ if (this._options.forever) {
43386
+ this._cachedTimeouts = this._timeouts.slice(0);
43387
+ }
43388
+ }
43389
+ module.exports = RetryOperation;
43390
+ RetryOperation.prototype.reset = function() {
43391
+ this._attempts = 1;
43392
+ this._timeouts = this._originalTimeouts.slice(0);
43393
+ };
43394
+ RetryOperation.prototype.stop = function() {
43395
+ if (this._timeout) {
43396
+ clearTimeout(this._timeout);
43397
+ }
43398
+ if (this._timer) {
43399
+ clearTimeout(this._timer);
43400
+ }
43401
+ this._timeouts = [];
43402
+ this._cachedTimeouts = null;
43403
+ };
43404
+ RetryOperation.prototype.retry = function(err) {
43405
+ if (this._timeout) {
43406
+ clearTimeout(this._timeout);
43407
+ }
43408
+ if (!err) {
43409
+ return false;
43410
+ }
43411
+ var currentTime = new Date().getTime();
43412
+ if (err && currentTime - this._operationStart >= this._maxRetryTime) {
43413
+ this._errors.push(err);
43414
+ this._errors.unshift(new Error("RetryOperation timeout occurred"));
43415
+ return false;
43416
+ }
43417
+ this._errors.push(err);
43418
+ var timeout = this._timeouts.shift();
43419
+ if (timeout === undefined) {
43420
+ if (this._cachedTimeouts) {
43421
+ this._errors.splice(0, this._errors.length - 1);
43422
+ timeout = this._cachedTimeouts.slice(-1);
43423
+ } else {
43424
+ return false;
43425
+ }
43426
+ }
43427
+ var self2 = this;
43428
+ this._timer = setTimeout(function() {
43429
+ self2._attempts++;
43430
+ if (self2._operationTimeoutCb) {
43431
+ self2._timeout = setTimeout(function() {
43432
+ self2._operationTimeoutCb(self2._attempts);
43433
+ }, self2._operationTimeout);
43434
+ if (self2._options.unref) {
43435
+ self2._timeout.unref();
43436
+ }
43437
+ }
43438
+ self2._fn(self2._attempts);
43439
+ }, timeout);
43440
+ if (this._options.unref) {
43441
+ this._timer.unref();
43442
+ }
43443
+ return true;
43444
+ };
43445
+ RetryOperation.prototype.attempt = function(fn, timeoutOps) {
43446
+ this._fn = fn;
43447
+ if (timeoutOps) {
43448
+ if (timeoutOps.timeout) {
43449
+ this._operationTimeout = timeoutOps.timeout;
43450
+ }
43451
+ if (timeoutOps.cb) {
43452
+ this._operationTimeoutCb = timeoutOps.cb;
43453
+ }
43454
+ }
43455
+ var self2 = this;
43456
+ if (this._operationTimeoutCb) {
43457
+ this._timeout = setTimeout(function() {
43458
+ self2._operationTimeoutCb();
43459
+ }, self2._operationTimeout);
43460
+ }
43461
+ this._operationStart = new Date().getTime();
43462
+ this._fn(this._attempts);
43463
+ };
43464
+ RetryOperation.prototype.try = function(fn) {
43465
+ console.log("Using RetryOperation.try() is deprecated");
43466
+ this.attempt(fn);
43467
+ };
43468
+ RetryOperation.prototype.start = function(fn) {
43469
+ console.log("Using RetryOperation.start() is deprecated");
43470
+ this.attempt(fn);
43471
+ };
43472
+ RetryOperation.prototype.start = RetryOperation.prototype.try;
43473
+ RetryOperation.prototype.errors = function() {
43474
+ return this._errors;
43475
+ };
43476
+ RetryOperation.prototype.attempts = function() {
43477
+ return this._attempts;
43478
+ };
43479
+ RetryOperation.prototype.mainError = function() {
43480
+ if (this._errors.length === 0) {
43481
+ return null;
43482
+ }
43483
+ var counts = {};
43484
+ var mainError = null;
43485
+ var mainErrorCount = 0;
43486
+ for (var i = 0;i < this._errors.length; i++) {
43487
+ var error = this._errors[i];
43488
+ var message = error.message;
43489
+ var count = (counts[message] || 0) + 1;
43490
+ counts[message] = count;
43491
+ if (count >= mainErrorCount) {
43492
+ mainError = error;
43493
+ mainErrorCount = count;
43494
+ }
43495
+ }
43496
+ return mainError;
43497
+ };
43498
+ });
43499
+
43500
+ // ../../node_modules/retry/lib/retry.js
43501
+ var require_retry = __commonJS((exports) => {
43502
+ var RetryOperation = require_retry_operation();
43503
+ exports.operation = function(options) {
43504
+ var timeouts = exports.timeouts(options);
43505
+ return new RetryOperation(timeouts, {
43506
+ forever: options && (options.forever || options.retries === Infinity),
43507
+ unref: options && options.unref,
43508
+ maxRetryTime: options && options.maxRetryTime
43509
+ });
43510
+ };
43511
+ exports.timeouts = function(options) {
43512
+ if (options instanceof Array) {
43513
+ return [].concat(options);
43514
+ }
43515
+ var opts = {
43516
+ retries: 10,
43517
+ factor: 2,
43518
+ minTimeout: 1 * 1000,
43519
+ maxTimeout: Infinity,
43520
+ randomize: false
43521
+ };
43522
+ for (var key in options) {
43523
+ opts[key] = options[key];
43524
+ }
43525
+ if (opts.minTimeout > opts.maxTimeout) {
43526
+ throw new Error("minTimeout is greater than maxTimeout");
43527
+ }
43528
+ var timeouts = [];
43529
+ for (var i = 0;i < opts.retries; i++) {
43530
+ timeouts.push(this.createTimeout(i, opts));
43531
+ }
43532
+ if (options && options.forever && !timeouts.length) {
43533
+ timeouts.push(this.createTimeout(i, opts));
43534
+ }
43535
+ timeouts.sort(function(a, b) {
43536
+ return a - b;
43537
+ });
43538
+ return timeouts;
43539
+ };
43540
+ exports.createTimeout = function(attempt, opts) {
43541
+ var random = opts.randomize ? Math.random() + 1 : 1;
43542
+ var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
43543
+ timeout = Math.min(timeout, opts.maxTimeout);
43544
+ return timeout;
43545
+ };
43546
+ exports.wrap = function(obj, options, methods) {
43547
+ if (options instanceof Array) {
43548
+ methods = options;
43549
+ options = null;
43550
+ }
43551
+ if (!methods) {
43552
+ methods = [];
43553
+ for (var key in obj) {
43554
+ if (typeof obj[key] === "function") {
43555
+ methods.push(key);
43556
+ }
43557
+ }
43558
+ }
43559
+ for (var i = 0;i < methods.length; i++) {
43560
+ var method = methods[i];
43561
+ var original = obj[method];
43562
+ obj[method] = function retryWrapper(original2) {
43563
+ var op = exports.operation(options);
43564
+ var args = Array.prototype.slice.call(arguments, 1);
43565
+ var callback = args.pop();
43566
+ args.push(function(err) {
43567
+ if (op.retry(err)) {
43568
+ return;
43569
+ }
43570
+ if (err) {
43571
+ arguments[0] = op.mainError();
43572
+ }
43573
+ callback.apply(this, arguments);
43574
+ });
43575
+ op.attempt(function() {
43576
+ original2.apply(obj, args);
43577
+ });
43578
+ }.bind(obj, original);
43579
+ obj[method].options = options;
43580
+ }
43581
+ };
43582
+ });
43583
+
43367
43584
  // ../../node_modules/safe-buffer/index.js
43368
43585
  var require_safe_buffer = __commonJS((exports, module) => {
43369
43586
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -46389,7 +46606,7 @@ var require_lodash = __commonJS((exports, module) => {
46389
46606
  }
46390
46607
  var objectProto = Object.prototype;
46391
46608
  var hasOwnProperty = objectProto.hasOwnProperty;
46392
- var objectToString = objectProto.toString;
46609
+ var objectToString2 = objectProto.toString;
46393
46610
  var propertyIsEnumerable = objectProto.propertyIsEnumerable;
46394
46611
  var nativeKeys = overArg(Object.keys, Object);
46395
46612
  var nativeMax = Math.max;
@@ -46433,7 +46650,7 @@ var require_lodash = __commonJS((exports, module) => {
46433
46650
  return isString(collection) ? fromIndex <= length && collection.indexOf(value, fromIndex) > -1 : !!length && baseIndexOf(collection, value, fromIndex) > -1;
46434
46651
  }
46435
46652
  function isArguments(value) {
46436
- return isArrayLikeObject(value) && hasOwnProperty.call(value, "callee") && (!propertyIsEnumerable.call(value, "callee") || objectToString.call(value) == argsTag);
46653
+ return isArrayLikeObject(value) && hasOwnProperty.call(value, "callee") && (!propertyIsEnumerable.call(value, "callee") || objectToString2.call(value) == argsTag);
46437
46654
  }
46438
46655
  var isArray = Array.isArray;
46439
46656
  function isArrayLike(value) {
@@ -46443,7 +46660,7 @@ var require_lodash = __commonJS((exports, module) => {
46443
46660
  return isObjectLike(value) && isArrayLike(value);
46444
46661
  }
46445
46662
  function isFunction(value) {
46446
- var tag = isObject(value) ? objectToString.call(value) : "";
46663
+ var tag = isObject(value) ? objectToString2.call(value) : "";
46447
46664
  return tag == funcTag || tag == genTag;
46448
46665
  }
46449
46666
  function isLength(value) {
@@ -46457,10 +46674,10 @@ var require_lodash = __commonJS((exports, module) => {
46457
46674
  return !!value && typeof value == "object";
46458
46675
  }
46459
46676
  function isString(value) {
46460
- return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag;
46677
+ return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString2.call(value) == stringTag;
46461
46678
  }
46462
46679
  function isSymbol(value) {
46463
- return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
46680
+ return typeof value == "symbol" || isObjectLike(value) && objectToString2.call(value) == symbolTag;
46464
46681
  }
46465
46682
  function toFinite(value) {
46466
46683
  if (!value) {
@@ -46508,9 +46725,9 @@ var require_lodash = __commonJS((exports, module) => {
46508
46725
  var require_lodash2 = __commonJS((exports, module) => {
46509
46726
  var boolTag = "[object Boolean]";
46510
46727
  var objectProto = Object.prototype;
46511
- var objectToString = objectProto.toString;
46728
+ var objectToString2 = objectProto.toString;
46512
46729
  function isBoolean(value) {
46513
- return value === true || value === false || isObjectLike(value) && objectToString.call(value) == boolTag;
46730
+ return value === true || value === false || isObjectLike(value) && objectToString2.call(value) == boolTag;
46514
46731
  }
46515
46732
  function isObjectLike(value) {
46516
46733
  return !!value && typeof value == "object";
@@ -46530,7 +46747,7 @@ var require_lodash3 = __commonJS((exports, module) => {
46530
46747
  var reIsOctal = /^0o[0-7]+$/i;
46531
46748
  var freeParseInt = parseInt;
46532
46749
  var objectProto = Object.prototype;
46533
- var objectToString = objectProto.toString;
46750
+ var objectToString2 = objectProto.toString;
46534
46751
  function isInteger(value) {
46535
46752
  return typeof value == "number" && value == toInteger(value);
46536
46753
  }
@@ -46542,7 +46759,7 @@ var require_lodash3 = __commonJS((exports, module) => {
46542
46759
  return !!value && typeof value == "object";
46543
46760
  }
46544
46761
  function isSymbol(value) {
46545
- return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
46762
+ return typeof value == "symbol" || isObjectLike(value) && objectToString2.call(value) == symbolTag;
46546
46763
  }
46547
46764
  function toFinite(value) {
46548
46765
  if (!value) {
@@ -46584,12 +46801,12 @@ var require_lodash3 = __commonJS((exports, module) => {
46584
46801
  var require_lodash4 = __commonJS((exports, module) => {
46585
46802
  var numberTag = "[object Number]";
46586
46803
  var objectProto = Object.prototype;
46587
- var objectToString = objectProto.toString;
46804
+ var objectToString2 = objectProto.toString;
46588
46805
  function isObjectLike(value) {
46589
46806
  return !!value && typeof value == "object";
46590
46807
  }
46591
46808
  function isNumber(value) {
46592
- return typeof value == "number" || isObjectLike(value) && objectToString.call(value) == numberTag;
46809
+ return typeof value == "number" || isObjectLike(value) && objectToString2.call(value) == numberTag;
46593
46810
  }
46594
46811
  module.exports = isNumber;
46595
46812
  });
@@ -46617,13 +46834,13 @@ var require_lodash5 = __commonJS((exports, module) => {
46617
46834
  var funcToString = funcProto.toString;
46618
46835
  var hasOwnProperty = objectProto.hasOwnProperty;
46619
46836
  var objectCtorString = funcToString.call(Object);
46620
- var objectToString = objectProto.toString;
46837
+ var objectToString2 = objectProto.toString;
46621
46838
  var getPrototype = overArg(Object.getPrototypeOf, Object);
46622
46839
  function isObjectLike(value) {
46623
46840
  return !!value && typeof value == "object";
46624
46841
  }
46625
46842
  function isPlainObject(value) {
46626
- if (!isObjectLike(value) || objectToString.call(value) != objectTag || isHostObject(value)) {
46843
+ if (!isObjectLike(value) || objectToString2.call(value) != objectTag || isHostObject(value)) {
46627
46844
  return false;
46628
46845
  }
46629
46846
  var proto = getPrototype(value);
@@ -46640,13 +46857,13 @@ var require_lodash5 = __commonJS((exports, module) => {
46640
46857
  var require_lodash6 = __commonJS((exports, module) => {
46641
46858
  var stringTag = "[object String]";
46642
46859
  var objectProto = Object.prototype;
46643
- var objectToString = objectProto.toString;
46860
+ var objectToString2 = objectProto.toString;
46644
46861
  var isArray = Array.isArray;
46645
46862
  function isObjectLike(value) {
46646
46863
  return !!value && typeof value == "object";
46647
46864
  }
46648
46865
  function isString(value) {
46649
- return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag;
46866
+ return typeof value == "string" || !isArray(value) && isObjectLike(value) && objectToString2.call(value) == stringTag;
46650
46867
  }
46651
46868
  module.exports = isString;
46652
46869
  });
@@ -46664,7 +46881,7 @@ var require_lodash7 = __commonJS((exports, module) => {
46664
46881
  var reIsOctal = /^0o[0-7]+$/i;
46665
46882
  var freeParseInt = parseInt;
46666
46883
  var objectProto = Object.prototype;
46667
- var objectToString = objectProto.toString;
46884
+ var objectToString2 = objectProto.toString;
46668
46885
  function before(n, func) {
46669
46886
  var result;
46670
46887
  if (typeof func != "function") {
@@ -46692,7 +46909,7 @@ var require_lodash7 = __commonJS((exports, module) => {
46692
46909
  return !!value && typeof value == "object";
46693
46910
  }
46694
46911
  function isSymbol(value) {
46695
- return typeof value == "symbol" || isObjectLike(value) && objectToString.call(value) == symbolTag;
46912
+ return typeof value == "symbol" || isObjectLike(value) && objectToString2.call(value) == symbolTag;
46696
46913
  }
46697
46914
  function toFinite(value) {
46698
46915
  if (!value) {
@@ -60350,6 +60567,12 @@ var handleFile = async (hookObject) => {
60350
60567
  var defaultBeforeCreateUpload = (hookObject) => handleFile(hookObject);
60351
60568
  var defaultBeforeUpdateUpload = (hookObject) => handleFile(hookObject);
60352
60569
 
60570
+ // src/utils/export.ts
60571
+ var contextWithRoot = (context) => ({
60572
+ ...context,
60573
+ isRoot: true
60574
+ });
60575
+
60353
60576
  // src/hooks/HookObject.ts
60354
60577
  class HookObject {
60355
60578
  className;
@@ -61192,6 +61415,110 @@ var gql = (chunks, ...variables) => {
61192
61415
 
61193
61416
  // src/database/adapters/MongoAdapter.ts
61194
61417
  var import_mongodb = __toESM(require_lib5(), 1);
61418
+
61419
+ // ../../node_modules/p-retry/index.js
61420
+ var import_retry = __toESM(require_retry(), 1);
61421
+
61422
+ // ../../node_modules/is-network-error/index.js
61423
+ var objectToString = Object.prototype.toString;
61424
+ var isError = (value) => objectToString.call(value) === "[object Error]";
61425
+ var errorMessages = new Set([
61426
+ "network error",
61427
+ "Failed to fetch",
61428
+ "NetworkError when attempting to fetch resource.",
61429
+ "The Internet connection appears to be offline.",
61430
+ "Load failed",
61431
+ "Network request failed",
61432
+ "fetch failed",
61433
+ "terminated"
61434
+ ]);
61435
+ function isNetworkError(error) {
61436
+ const isValid = error && isError(error) && error.name === "TypeError" && typeof error.message === "string";
61437
+ if (!isValid) {
61438
+ return false;
61439
+ }
61440
+ if (error.message === "Load failed") {
61441
+ return error.stack === undefined;
61442
+ }
61443
+ return errorMessages.has(error.message);
61444
+ }
61445
+
61446
+ // ../../node_modules/p-retry/index.js
61447
+ class AbortError extends Error {
61448
+ constructor(message) {
61449
+ super();
61450
+ if (message instanceof Error) {
61451
+ this.originalError = message;
61452
+ ({ message } = message);
61453
+ } else {
61454
+ this.originalError = new Error(message);
61455
+ this.originalError.stack = this.stack;
61456
+ }
61457
+ this.name = "AbortError";
61458
+ this.message = message;
61459
+ }
61460
+ }
61461
+ var decorateErrorWithCounts = (error, attemptNumber, options) => {
61462
+ const retriesLeft = options.retries - (attemptNumber - 1);
61463
+ error.attemptNumber = attemptNumber;
61464
+ error.retriesLeft = retriesLeft;
61465
+ return error;
61466
+ };
61467
+ async function pRetry(input, options) {
61468
+ return new Promise((resolve, reject) => {
61469
+ options = { ...options };
61470
+ options.onFailedAttempt ??= () => {
61471
+ };
61472
+ options.shouldRetry ??= () => true;
61473
+ options.retries ??= 10;
61474
+ const operation = import_retry.default.operation(options);
61475
+ const abortHandler = () => {
61476
+ operation.stop();
61477
+ reject(options.signal?.reason);
61478
+ };
61479
+ if (options.signal && !options.signal.aborted) {
61480
+ options.signal.addEventListener("abort", abortHandler, { once: true });
61481
+ }
61482
+ const cleanUp = () => {
61483
+ options.signal?.removeEventListener("abort", abortHandler);
61484
+ operation.stop();
61485
+ };
61486
+ operation.attempt(async (attemptNumber) => {
61487
+ try {
61488
+ const result = await input(attemptNumber);
61489
+ cleanUp();
61490
+ resolve(result);
61491
+ } catch (error) {
61492
+ try {
61493
+ if (!(error instanceof Error)) {
61494
+ throw new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
61495
+ }
61496
+ if (error instanceof AbortError) {
61497
+ throw error.originalError;
61498
+ }
61499
+ if (error instanceof TypeError && !isNetworkError(error)) {
61500
+ throw error;
61501
+ }
61502
+ decorateErrorWithCounts(error, attemptNumber, options);
61503
+ if (!await options.shouldRetry(error)) {
61504
+ operation.stop();
61505
+ reject(error);
61506
+ }
61507
+ await options.onFailedAttempt(error);
61508
+ if (!operation.retry(error)) {
61509
+ throw operation.mainError();
61510
+ }
61511
+ } catch (finalError) {
61512
+ decorateErrorWithCounts(finalError, attemptNumber, options);
61513
+ cleanUp();
61514
+ reject(finalError);
61515
+ }
61516
+ }
61517
+ });
61518
+ });
61519
+ }
61520
+
61521
+ // src/database/adapters/MongoAdapter.ts
61195
61522
  var buildMongoOrderQuery = (order) => {
61196
61523
  if (!order)
61197
61524
  return {};
@@ -61267,7 +61594,11 @@ class MongoAdapter {
61267
61594
  this.client = new import_mongodb.MongoClient(options.databaseUrl);
61268
61595
  }
61269
61596
  async connect() {
61270
- const client = await this.client.connect();
61597
+ const client = await pRetry(() => this.client.connect(), {
61598
+ retries: 5,
61599
+ minTimeout: 100,
61600
+ factor: 2
61601
+ });
61271
61602
  this.database = client.db(this.options.databaseName);
61272
61603
  return client;
61273
61604
  }
@@ -61390,10 +61721,7 @@ class MongoAdapter {
61390
61721
  fields: ["id"],
61391
61722
  offset,
61392
61723
  first,
61393
- context: {
61394
- ...context,
61395
- isRoot: true
61396
- },
61724
+ context: contextWithRoot(context),
61397
61725
  order
61398
61726
  });
61399
61727
  if (objectsBeforeUpdate.length === 0)
@@ -61636,10 +61964,7 @@ var initializeHook = ({
61636
61964
  return {};
61637
61965
  return context.wabe.controllers.database.getObject({
61638
61966
  className,
61639
- context: {
61640
- ...context,
61641
- isRoot: true
61642
- },
61967
+ context: contextWithRoot(context),
61643
61968
  id,
61644
61969
  skipHooks: true,
61645
61970
  fields: ["*"]
@@ -61653,10 +61978,7 @@ var initializeHook = ({
61653
61978
  return [{}];
61654
61979
  const res = await context.wabe.controllers.database.getObjects({
61655
61980
  className,
61656
- context: {
61657
- ...context,
61658
- isRoot: true
61659
- },
61981
+ context: contextWithRoot(context),
61660
61982
  where: where ? where : { id: { in: ids } },
61661
61983
  fields: ["*"],
61662
61984
  skipHooks: true
@@ -62139,10 +62461,7 @@ class DatabaseController2 {
62139
62461
  return null;
62140
62462
  return this.getObject({
62141
62463
  className,
62142
- context: {
62143
- ...context,
62144
- isRoot: true
62145
- },
62464
+ context: contextWithRoot(context),
62146
62465
  fields,
62147
62466
  id,
62148
62467
  skipHooks: true
@@ -62380,7 +62699,6 @@ var AuthenticationProvider;
62380
62699
  })(AuthenticationProvider ||= {});
62381
62700
  // src/authentication/Session.ts
62382
62701
  var import_jsonwebtoken = __toESM(require_jsonwebtoken(), 1);
62383
-
62384
62702
  class Session {
62385
62703
  accessToken = undefined;
62386
62704
  refreshToken = undefined;
@@ -62429,10 +62747,7 @@ class Session {
62429
62747
  }, import.meta.env.JWT_SECRET || "dev");
62430
62748
  const res = await context.wabe.controllers.database.createObject({
62431
62749
  className: "_Session",
62432
- context: {
62433
- ...context,
62434
- isRoot: true
62435
- },
62750
+ context: contextWithRoot(context),
62436
62751
  data: {
62437
62752
  accessToken: this.accessToken,
62438
62753
  accessTokenExpiresAt: this.getAccessTokenExpireAt(context.wabe.config),
@@ -62455,10 +62770,7 @@ class Session {
62455
62770
  return;
62456
62771
  await context.wabe.controllers.database.deleteObject({
62457
62772
  className: "_Session",
62458
- context: {
62459
- ...context,
62460
- isRoot: true
62461
- },
62773
+ context: contextWithRoot(context),
62462
62774
  id: context.sessionId,
62463
62775
  fields: []
62464
62776
  });
@@ -62475,10 +62787,7 @@ class Session {
62475
62787
  accessToken: { equalTo: accessToken }
62476
62788
  },
62477
62789
  fields: ["id", "user", "refreshToken", "refreshTokenExpiresAt"],
62478
- context: {
62479
- ...context,
62480
- isRoot: true
62481
- }
62790
+ context: contextWithRoot(context)
62482
62791
  });
62483
62792
  if (!session.length)
62484
62793
  return {
@@ -62521,10 +62830,7 @@ class Session {
62521
62830
  }, import.meta.env.JWT_SECRET || "dev");
62522
62831
  await context.wabe.controllers.database.updateObject({
62523
62832
  className: "_Session",
62524
- context: {
62525
- ...context,
62526
- isRoot: true
62527
- },
62833
+ context: contextWithRoot(context),
62528
62834
  id,
62529
62835
  data: {
62530
62836
  accessToken: newAccessToken,
@@ -62597,10 +62903,7 @@ var signUpWithResolver = async (_, {
62597
62903
  const session = new Session;
62598
62904
  if (!createdUserId)
62599
62905
  throw new Error("User not created");
62600
- const { accessToken, refreshToken } = await session.create(createdUserId, {
62601
- ...context,
62602
- isRoot: true
62603
- });
62906
+ const { accessToken, refreshToken } = await session.create(createdUserId, contextWithRoot(context));
62604
62907
  if (context.wabe.config.authentication?.session?.cookieSession) {
62605
62908
  context.response?.setCookie("refreshToken", refreshToken, {
62606
62909
  httpOnly: true,
@@ -62862,10 +63165,7 @@ var resetPasswordResolver = async (_, { input: { email, password, otp, provider
62862
63165
  },
62863
63166
  fields: ["id"],
62864
63167
  first: 1,
62865
- context: {
62866
- ...context,
62867
- isRoot: true
62868
- }
63168
+ context: contextWithRoot(context)
62869
63169
  });
62870
63170
  if (user.length === 0)
62871
63171
  return true;
@@ -62890,10 +63190,7 @@ var resetPasswordResolver = async (_, { input: { email, password, otp, provider
62890
63190
  }
62891
63191
  },
62892
63192
  fields: [],
62893
- context: {
62894
- ...context,
62895
- isRoot: true
62896
- }
63193
+ context: contextWithRoot(context)
62897
63194
  });
62898
63195
  return true;
62899
63196
  };
@@ -63034,10 +63331,7 @@ var sendOtpCodeResolver = async (_, { input }, context) => {
63034
63331
  },
63035
63332
  fields: ["id"],
63036
63333
  first: 1,
63037
- context: {
63038
- ...context,
63039
- isRoot: true
63040
- }
63334
+ context: contextWithRoot(context)
63041
63335
  });
63042
63336
  if (user.length === 0)
63043
63337
  return true;
@@ -65386,10 +65680,7 @@ class EmailPassword {
65386
65680
  }
65387
65681
  }
65388
65682
  },
65389
- context: {
65390
- ...context,
65391
- isRoot: true
65392
- },
65683
+ context: contextWithRoot(context),
65393
65684
  fields: ["id", "authentication"],
65394
65685
  first: 1
65395
65686
  });
@@ -65467,15 +65758,7 @@ class Google3 {
65467
65758
  }) {
65468
65759
  const { authorizationCode, codeVerifier } = input;
65469
65760
  const googleOauth = new Google(context.wabe.config);
65470
- const {
65471
- accessToken,
65472
- refreshToken,
65473
- idToken,
65474
- accessTokenExpiresAt,
65475
- refreshTokenExpiresAt
65476
- } = await googleOauth.validateAuthorizationCode(authorizationCode, codeVerifier);
65477
- if (!refreshToken)
65478
- throw new Error("Access_type must be offline");
65761
+ const { accessToken, idToken } = await googleOauth.validateAuthorizationCode(authorizationCode, codeVerifier);
65479
65762
  if (!idToken)
65480
65763
  throw new Error("Authentication failed");
65481
65764
  const { email, verifiedEmail } = await googleOauth.getUserInfo(accessToken, idToken);
@@ -65488,10 +65771,7 @@ class Google3 {
65488
65771
  }
65489
65772
  }
65490
65773
  },
65491
- context: {
65492
- ...context,
65493
- isRoot: true
65494
- },
65774
+ context: contextWithRoot(context),
65495
65775
  first: 1,
65496
65776
  fields: ["id"]
65497
65777
  });
@@ -65510,34 +65790,19 @@ class Google3 {
65510
65790
  google: authenticationDataToSave
65511
65791
  }
65512
65792
  },
65513
- context: {
65514
- ...context,
65515
- isRoot: true
65516
- },
65793
+ context: contextWithRoot(context),
65517
65794
  fields: ["*", "id"]
65518
65795
  });
65519
65796
  if (!createdUser)
65520
65797
  throw new Error("User not found");
65521
65798
  return {
65522
- user: createdUser,
65523
- oauth: {
65524
- refreshToken,
65525
- accessToken,
65526
- accessTokenExpiresAt: accessTokenExpiresAt || new Date,
65527
- refreshTokenExpiresAt: refreshTokenExpiresAt || new Date
65528
- }
65799
+ user: createdUser
65529
65800
  };
65530
65801
  }
65531
65802
  if (!user[0])
65532
65803
  throw new Error("User not found");
65533
65804
  return {
65534
- user: user[0],
65535
- oauth: {
65536
- refreshToken,
65537
- accessToken,
65538
- accessTokenExpiresAt: accessTokenExpiresAt || new Date,
65539
- refreshTokenExpiresAt: refreshTokenExpiresAt || new Date
65540
- }
65805
+ user: user[0]
65541
65806
  };
65542
65807
  }
65543
65808
  onSignIn(options) {
@@ -75923,6 +76188,7 @@ export {
75923
76188
  initializeHook,
75924
76189
  getDefaultHooks,
75925
76190
  generateCodegen,
76191
+ contextWithRoot,
75926
76192
  buildMongoWhereQuery,
75927
76193
  buildMongoOrderQuery,
75928
76194
  _findHooksByPriority,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wabe",
3
- "version": "0.5.21",
3
+ "version": "0.5.22",
4
4
  "description": "Your backend in minutes not days",
5
5
  "homepage": "https://wabe.dev",
6
6
  "author": {
@@ -31,18 +31,17 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@graphql-yoga/plugin-disable-introspection": "2.10.9",
34
- "@graphql-tools/graphql-file-loader": "8.0.1",
35
- "@graphql-tools/load": "8.0.2",
36
34
  "@node-rs/argon2": "2.0.0",
37
35
  "jsonwebtoken": "9.0.2",
38
36
  "mongodb": "6.8.0",
39
37
  "otplib": "12.0.1",
38
+ "p-retry": "6.2.1",
40
39
  "wobe": "1.1.9",
41
40
  "wobe-graphql-yoga": "1.2.5"
42
41
  },
43
42
  "devDependencies": {
44
43
  "@parcel/watcher": "2.3.0",
45
- "@types/bun": "1.1.8",
44
+ "@types/bun": "latest",
46
45
  "@types/jsonwebtoken": "9.0.6",
47
46
  "@types/uuid": "9.0.6",
48
47
  "dts-bundle-generator": "9.5.1",