@eyepop.ai/eyepop 3.17.2 → 3.18.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.
@@ -8632,6 +8632,40 @@ var require_mime_types = __commonJS({
8632
8632
  }
8633
8633
  });
8634
8634
 
8635
+ // options.ts
8636
+ function nonEmptyCredential(value) {
8637
+ return value && value.length > 0 ? value : void 0;
8638
+ }
8639
+ function resolveAuth(options) {
8640
+ const apiKey = nonEmptyCredential(options.apiKey);
8641
+ if (apiKey !== void 0) {
8642
+ return { apiKey };
8643
+ }
8644
+ const accessToken = nonEmptyCredential(options.accessToken);
8645
+ if (accessToken !== void 0) {
8646
+ return { accessToken };
8647
+ }
8648
+ if (options.session !== void 0) {
8649
+ return { session: options.session };
8650
+ }
8651
+ if (options.oAuth2 !== void 0) {
8652
+ return { oAuth2: options.oAuth2 };
8653
+ }
8654
+ return options.auth;
8655
+ }
8656
+ function apiKeyCredential(auth) {
8657
+ if (auth === void 0) {
8658
+ return void 0;
8659
+ }
8660
+ return nonEmptyCredential(auth.apiKey);
8661
+ }
8662
+ function accessTokenCredential(auth) {
8663
+ if (auth === void 0) {
8664
+ return void 0;
8665
+ }
8666
+ return nonEmptyCredential(auth.accessToken);
8667
+ }
8668
+
8635
8669
  // compute/compute_session.ts
8636
8670
  var SESSION_DEAD = /* @__PURE__ */ new Set(["error" /* ERROR */, "failed" /* FAILED */, "stopped" /* STOPPED */, "pipeline_error" /* PIPELINE_ERROR */, "unknown" /* UNKNOWN */]);
8637
8671
  var CHECK_FOR_IS_READY_INTERVAL = 250;
@@ -10470,17 +10504,19 @@ var Endpoint = class {
10470
10504
  if (!this._options.eyepopUrl) {
10471
10505
  return Promise.reject("option eyepopUrl or environment variable EYEPOP_URL is required");
10472
10506
  }
10473
- if (this._options.auth === void 0) {
10507
+ const auth = resolveAuth(this._options);
10508
+ if (auth === void 0) {
10474
10509
  return Promise.reject("cannot connect without defined auth option");
10475
10510
  }
10476
- if (this._options.auth.session !== void 0) {
10477
- this._token = this._options.auth.session.accessToken;
10478
- this._expire_token_time = this._options.auth.session.validUntil / 1e3;
10479
- } else if (this._options.auth.oAuth2 !== void 0) {
10480
- } else if (this._options.auth.apiKey !== void 0) {
10481
- } else if (this._options.auth.isLocal !== void 0) {
10511
+ if (auth.session !== void 0) {
10512
+ this._token = auth.session.accessToken;
10513
+ this._expire_token_time = auth.session.validUntil / 1e3;
10514
+ } else if (auth.oAuth2 !== void 0) {
10515
+ } else if (accessTokenCredential(auth) !== void 0) {
10516
+ } else if (apiKeyCredential(auth) !== void 0) {
10517
+ } else if (auth.isLocal !== void 0) {
10482
10518
  } else {
10483
- return Promise.reject("option apiKey or environment variable EYEPOP_API_KEY is required");
10519
+ return Promise.reject("option apiKey/accessToken or environment variable EYEPOP_API_KEY is required");
10484
10520
  }
10485
10521
  if (this._options.platformSupport?.createHttpClient !== void 0) {
10486
10522
  this._client = await this._options.platformSupport.createHttpClient(this._requestLogger);
@@ -10554,7 +10590,7 @@ var Endpoint = class {
10554
10590
  throw new Error("reconnect() not implemented");
10555
10591
  }
10556
10592
  async authorizationHeader() {
10557
- if (this._options.auth.isLocal !== void 0) {
10593
+ if (resolveAuth(this._options)?.isLocal !== void 0) {
10558
10594
  return `Implicit`;
10559
10595
  }
10560
10596
  return `Bearer ${await this.currentAccessToken()}`;
@@ -10564,19 +10600,27 @@ var Endpoint = class {
10564
10600
  if (!this._token || this._expire_token_time < now) {
10565
10601
  this.updateState("Authenticating" /* Authenticating */);
10566
10602
  try {
10603
+ const auth = resolveAuth(this._options);
10567
10604
  if (!this._client) {
10568
10605
  return Promise.reject("endpoint not connected");
10569
- } else if (this._options.auth.isLocal !== void 0) {
10606
+ } else if (auth?.isLocal !== void 0) {
10570
10607
  this._token = "implicit";
10571
10608
  this._expire_token_time = Number.MAX_VALUE;
10572
- } else if (this._options.auth.session !== void 0) {
10609
+ } else if (auth?.session !== void 0) {
10573
10610
  return Promise.reject("temporary access token expired");
10574
- } else if (this._options.auth.oAuth2 !== void 0 && this._options.eyepopUrl) {
10575
- const session = await authenticateBrowserSession(this._options.auth.oAuth2, this._options);
10611
+ } else if (auth?.oAuth2 !== void 0 && this._options.eyepopUrl) {
10612
+ const session = await authenticateBrowserSession(auth.oAuth2, this._options);
10576
10613
  this._token = session.accessToken;
10577
10614
  this._expire_token_time = session.validUntil / 1e3;
10578
- } else if (this._options.auth.apiKey !== void 0 && this._options.eyepopUrl) {
10579
- const headers = { "Authorization": `Bearer ${this._options.auth.apiKey}` };
10615
+ } else if (accessTokenCredential(auth) !== void 0) {
10616
+ this._token = accessTokenCredential(auth);
10617
+ this._expire_token_time = Number.MAX_VALUE;
10618
+ } else if (this._options.eyepopUrl) {
10619
+ const credential = apiKeyCredential(auth);
10620
+ if (credential === void 0) {
10621
+ return Promise.reject("no valid auth option");
10622
+ }
10623
+ const headers = { Authorization: `Bearer ${credential}` };
10580
10624
  const post_url = `${this.eyepopUrl()}/v1/auth/authenticate`;
10581
10625
  const response = await this._client.fetch(post_url, {
10582
10626
  method: "POST",
@@ -10721,7 +10765,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10721
10765
  }
10722
10766
  }
10723
10767
  _authenticationHeaders(session) {
10724
- return this._options.auth.isLocal !== void 0 ? {} : { Authorization: `Bearer ${session.accessToken}` };
10768
+ return resolveAuth(this._options)?.isLocal !== void 0 ? {} : { Authorization: `Bearer ${session.accessToken}` };
10725
10769
  }
10726
10770
  /**
10727
10771
  * @deprecated Pop ids are only retained for backwards compatibility.
@@ -10792,13 +10836,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10792
10836
  return { stream: streamSource.stream, mimeType: streamSource.mimeType };
10793
10837
  })
10794
10838
  );
10795
- const job = new UploadGroupJob(
10796
- sources,
10797
- params,
10798
- async () => this.session(),
10799
- this._client,
10800
- this._requestLogger
10801
- );
10839
+ const job = new UploadGroupJob(sources, params, async () => this.session(), this._client, this._requestLogger);
10802
10840
  return job.start(
10803
10841
  () => {
10804
10842
  this.jobDone(job);
@@ -10829,13 +10867,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10829
10867
  stream,
10830
10868
  mimeType: mimeTypes?.[i] ?? null
10831
10869
  }));
10832
- const job = new UploadGroupJob(
10833
- sources,
10834
- params,
10835
- async () => this.session(),
10836
- this._client,
10837
- this._requestLogger
10838
- );
10870
+ const job = new UploadGroupJob(sources, params, async () => this.session(), this._client, this._requestLogger);
10839
10871
  return job.start(
10840
10872
  () => {
10841
10873
  this.jobDone(job);
@@ -10859,13 +10891,7 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
10859
10891
  await this._limit.acquire();
10860
10892
  try {
10861
10893
  this.updateState();
10862
- const job = new LoadFromGroupJob(
10863
- urls,
10864
- params,
10865
- async () => this.session(),
10866
- this._client,
10867
- this._requestLogger
10868
- );
10894
+ const job = new LoadFromGroupJob(urls, params, async () => this.session(), this._client, this._requestLogger);
10869
10895
  return job.start(
10870
10896
  () => {
10871
10897
  this.jobDone(job);
@@ -11368,11 +11394,13 @@ var _WorkerEndpoint = class _WorkerEndpoint extends Endpoint {
11368
11394
  return super.authorizationHeader();
11369
11395
  }
11370
11396
  async computeAuthorizationHeader() {
11371
- if (this.options().auth.isLocal !== void 0) {
11397
+ const auth = resolveAuth(this.options());
11398
+ if (auth?.isLocal !== void 0) {
11372
11399
  return "Implicit";
11373
11400
  }
11374
- if (this.options().auth.apiKey !== void 0) {
11375
- return `Bearer ${this.options().auth.apiKey}`;
11401
+ const credential = apiKeyCredential(auth) ?? accessTokenCredential(auth);
11402
+ if (credential !== void 0) {
11403
+ return `Bearer ${credential}`;
11376
11404
  }
11377
11405
  return super.authorizationHeader();
11378
11406
  }
@@ -11823,8 +11851,8 @@ var DataEndpoint = class extends Endpoint {
11823
11851
  this._accountId = options.accountId || null;
11824
11852
  this._account_event_handlers = [];
11825
11853
  this._dataset_uuid_to_event_handlers = /* @__PURE__ */ new Map();
11826
- const sessionAuth = options.auth;
11827
- if (sessionAuth.session !== void 0) {
11854
+ const sessionAuth = resolveAuth(options);
11855
+ if (sessionAuth?.session !== void 0) {
11828
11856
  const dataSession = sessionAuth.session;
11829
11857
  if (dataSession.accountId) {
11830
11858
  this._accountId = dataSession.accountId;
@@ -12752,11 +12780,11 @@ var EyePop;
12752
12780
  opts.eyepopUrl = "http://127.0.0.1:8080";
12753
12781
  }
12754
12782
  _fill_default_options(opts);
12755
- if (opts.auth === void 0) {
12783
+ if (resolveAuth(opts) === void 0) {
12756
12784
  if (opts.isLocalMode) {
12757
12785
  opts.auth = { isLocal: true };
12758
12786
  } else {
12759
- throw new Error("auth option or EYEPOP_API_KEY environment variable is required");
12787
+ throw new Error("apiKey/accessToken/session/oAuth2 option or EYEPOP_API_KEY environment variable is required");
12760
12788
  }
12761
12789
  }
12762
12790
  if (opts.sessionUuid === void 0) {
@@ -12780,11 +12808,12 @@ var EyePop;
12780
12808
  if (opts.stopJobs === void 0) {
12781
12809
  opts.stopJobs = true;
12782
12810
  }
12783
- if (opts.auth !== void 0) {
12784
- if (opts.auth.session !== void 0) {
12785
- if (opts.auth.session !== void 0) {
12786
- if (opts.auth.session.popId) {
12787
- opts.popId = opts.auth.session.popId;
12811
+ const auth = resolveAuth(opts);
12812
+ if (auth !== void 0) {
12813
+ if (auth.session !== void 0) {
12814
+ if (auth.session !== void 0) {
12815
+ if (auth.session.popId) {
12816
+ opts.popId = auth.session.popId;
12788
12817
  }
12789
12818
  }
12790
12819
  }
@@ -12794,16 +12823,17 @@ var EyePop;
12794
12823
  EyePop2.workerEndpoint = workerEndpoint;
12795
12824
  function dataEndpoint(opts = {}) {
12796
12825
  _fill_default_options(opts);
12797
- if (opts.auth === void 0) {
12798
- throw new Error("auth option or EYEPOP_API_KEY environment variable is required");
12826
+ const auth = resolveAuth(opts);
12827
+ if (auth === void 0) {
12828
+ throw new Error("apiKey/accessToken/session/oAuth2 option or EYEPOP_API_KEY environment variable is required");
12799
12829
  }
12800
12830
  if (opts.accountId === void 0) {
12801
12831
  opts.accountId = readEnv("EYEPOP_ACCOUNT_ID");
12802
12832
  }
12803
- if (opts.auth.session !== void 0) {
12804
- if (opts.auth.session !== void 0) {
12805
- if (opts.auth.session.accountId) {
12806
- opts.accountId = opts.auth.session.accountId;
12833
+ if (auth.session !== void 0) {
12834
+ if (auth.session !== void 0) {
12835
+ if (auth.session.accountId) {
12836
+ opts.accountId = auth.session.accountId;
12807
12837
  }
12808
12838
  }
12809
12839
  }
@@ -12811,11 +12841,12 @@ var EyePop;
12811
12841
  }
12812
12842
  EyePop2.dataEndpoint = dataEndpoint;
12813
12843
  function _fill_default_options(opts) {
12814
- if (!opts.auth) {
12815
- opts.auth = defaultAuth;
12844
+ if (resolveAuth(opts) === void 0 && defaultAuth) {
12845
+ opts.apiKey = defaultAuth.apiKey;
12816
12846
  }
12817
- if (!opts.eyepopUrl && opts.auth && opts.auth.session && opts.auth.session.eyepopUrl) {
12818
- opts.eyepopUrl = opts.auth.session.eyepopUrl;
12847
+ const auth = resolveAuth(opts);
12848
+ if (!opts.eyepopUrl && auth && auth.session && auth.session.eyepopUrl) {
12849
+ opts.eyepopUrl = auth.session.eyepopUrl;
12819
12850
  }
12820
12851
  if (!opts.eyepopUrl) {
12821
12852
  opts.eyepopUrl = readEnv("EYEPOP_URL");
@@ -12823,27 +12854,28 @@ var EyePop;
12823
12854
  if (!opts.eyepopUrl) {
12824
12855
  opts.eyepopUrl = "https://compute.eyepop.ai";
12825
12856
  }
12826
- if (opts.auth) {
12827
- if (opts.auth.oAuth2 !== void 0) {
12828
- if (typeof opts.auth.oAuth2 === "boolean") {
12829
- if (opts.eyepopUrl && opts.eyepopUrl.match(/https:(.*).staging.eyepop.xyz/i)) {
12830
- opts.auth = {
12831
- oAuth2: {
12832
- domain: "dev-eyepop.us.auth0.com",
12833
- clientId: "jktx3YO2UnbkNPvr05PQWf26t1kNTJyg",
12834
- audience: "https://dev-app.eyepop.ai",
12835
- scope: "admin:clouds access:inference-api access:datasets"
12836
- }
12837
- };
12857
+ if (auth) {
12858
+ if (auth.oAuth2 !== void 0) {
12859
+ if (typeof auth.oAuth2 === "boolean") {
12860
+ const oAuth2 = opts.eyepopUrl && opts.eyepopUrl.match(/https:(.*).staging.eyepop.xyz/i) ? {
12861
+ oAuth2: {
12862
+ domain: "dev-eyepop.us.auth0.com",
12863
+ clientId: "jktx3YO2UnbkNPvr05PQWf26t1kNTJyg",
12864
+ audience: "https://dev-app.eyepop.ai",
12865
+ scope: "admin:clouds access:inference-api access:datasets"
12866
+ }
12867
+ } : {
12868
+ oAuth2: {
12869
+ domain: "eyepop.us.auth0.com",
12870
+ clientId: "Lb9ubA9Hf3jlaqWLUx8XgA0zvotgViCl",
12871
+ audience: "https://api.eyepop.ai",
12872
+ scope: "admin:clouds access:inference-api access:datasets"
12873
+ }
12874
+ };
12875
+ if (opts.oAuth2 !== void 0) {
12876
+ opts.oAuth2 = oAuth2.oAuth2;
12838
12877
  } else {
12839
- opts.auth = {
12840
- oAuth2: {
12841
- domain: "eyepop.us.auth0.com",
12842
- clientId: "Lb9ubA9Hf3jlaqWLUx8XgA0zvotgViCl",
12843
- audience: "https://api.eyepop.ai",
12844
- scope: "admin:clouds access:inference-api access:datasets"
12845
- }
12846
- };
12878
+ opts.auth = oAuth2;
12847
12879
  }
12848
12880
  }
12849
12881
  }
@@ -12908,11 +12940,14 @@ export {
12908
12940
  WebrtcWhip,
12909
12941
  WorkerEndpoint,
12910
12942
  WorkflowPhase,
12943
+ accessTokenCredential,
12944
+ apiKeyCredential,
12911
12945
  index_default as default,
12912
12946
  encodeMultipartFormData,
12913
12947
  getBaseUrl,
12914
12948
  randomMultipartBoundary,
12915
- readableStreamFromString
12949
+ readableStreamFromString,
12950
+ resolveAuth
12916
12951
  };
12917
12952
  /*! Bundled license information:
12918
12953