@streamoid/settings 0.22.3 → 0.22.4

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/README.md CHANGED
@@ -177,7 +177,9 @@ Billing hides an entry whose adapter method is absent:
177
177
  `formerMembers` (`poolSharesCredits`) gets a Workspace column in its usage
178
178
  logs, on every page: "This workspace", or "Used by <name>" for rows whose
179
179
  `meta.usedBy` is another workspace, named from those members. Without
180
- `fetchCreditPool` the column shows from the first loaded page with such a
180
+ `fetchCreditPool`, or when it fails (a 403 for a member who is not a
181
+ workspace admin; not asked again after a 4xx such as 401/403, once more
182
+ after a network error (no status, or status 0) or 5xx), the column shows from the first loaded page with such a
181
183
  row (every row, for an adapter that sends them all) and stays on every page
182
184
  until the workspace changes; those rows read "Used by another workspace".
183
185
  `setCreditPoolSelfShare` and `removeCreditPoolSelfShare` (mirroring
package/dist/index.d.mts CHANGED
@@ -1889,19 +1889,22 @@ declare function usageLogsReloadPage(state: UsageLogsState): number;
1889
1889
  /**
1890
1890
  * Whether the usage logs in hand have a row another workspace spent from this
1891
1891
  * one's shared credits. Every row an unpaged adapter sent counts, not only the
1892
- * page on screen.
1892
+ * page on screen. The Workspace column's decision without a credit pool to
1893
+ * read.
1893
1894
  */
1894
1895
  declare function usageLogsSpentByOthers(logs: UsageLogsPage, workspaceId: string | null | undefined): boolean;
1895
1896
  /**
1896
1897
  * Whether the Usage logs table shows its Workspace column: the same on every
1897
1898
  * page of a workspace's logs. With `fetchCreditPool`, whether the workspace
1898
- * shares its credits or did (`poolSharesCredits`). Without it, whether any
1899
- * page loaded for the workspace so far had a row another workspace spent:
1900
- * once shown it stays, on every page, until another workspace.
1899
+ * shares its credits or did (`poolSharesCredits`). Without it, or when the
1900
+ * pool could not be read (`failed`: a member who is not a workspace admin gets
1901
+ * a 403), whether any page loaded for the workspace so far had a row another
1902
+ * workspace spent: once shown it stays, on every page, until another workspace.
1901
1903
  */
1902
1904
  declare function usageLogsShowWorkspace(state: Pick<UsageLogsState, "spentByOthers">, pool: {
1903
1905
  hasCreditPool: boolean;
1904
1906
  sharesCredits: boolean;
1907
+ failed?: boolean;
1905
1908
  }): boolean;
1906
1909
  interface UsedByNamesLoader {
1907
1910
  /** Look up `workspaceId`'s names, unless they are saved or being looked up. */
@@ -1917,11 +1920,14 @@ interface UsedByNamesLoader {
1917
1920
  * workspaces that spent its shared credits, and the pool itself (whether it
1918
1921
  * shares them at all). `save` gets each answer and says whether it
1919
1922
  * kept it (false: that workspace is no longer shown); only a kept answer ends
1920
- * the lookups for that workspace. A failed or unkept lookup is tried again on
1921
- * the next call; a call while one for the same workspace is under way starts
1922
- * no other.
1923
- */
1924
- declare function createUsedByNamesLoader(save: (workspaceId: string, names: Record<string, string>, pool: CreditPoolResponse) => boolean): UsedByNamesLoader;
1923
+ * the lookups for that workspace. An unkept lookup is tried again on the next
1924
+ * call. A failed one calls `failed` (the Workspace column falls back to the
1925
+ * rows) and is tried once more on a later call when it was the network
1926
+ * (status 0 included) or a 5xx; a 4xx such as 401/403, or a second failure,
1927
+ * ends the lookups for that workspace until `reset`, so turning pages does not ask again. A call while
1928
+ * one for the same workspace is under way starts no other.
1929
+ */
1930
+ declare function createUsedByNamesLoader(save: (workspaceId: string, names: Record<string, string>, pool: CreditPoolResponse) => boolean, failed?: (workspaceId: string) => void): UsedByNamesLoader;
1925
1931
  /** The CSV file name for a picked day range, from its local calendar days. */
1926
1932
  declare function usageLogsExportFileName(start: Date, end: Date): string;
1927
1933
  /**
package/dist/index.d.ts CHANGED
@@ -1889,19 +1889,22 @@ declare function usageLogsReloadPage(state: UsageLogsState): number;
1889
1889
  /**
1890
1890
  * Whether the usage logs in hand have a row another workspace spent from this
1891
1891
  * one's shared credits. Every row an unpaged adapter sent counts, not only the
1892
- * page on screen.
1892
+ * page on screen. The Workspace column's decision without a credit pool to
1893
+ * read.
1893
1894
  */
1894
1895
  declare function usageLogsSpentByOthers(logs: UsageLogsPage, workspaceId: string | null | undefined): boolean;
1895
1896
  /**
1896
1897
  * Whether the Usage logs table shows its Workspace column: the same on every
1897
1898
  * page of a workspace's logs. With `fetchCreditPool`, whether the workspace
1898
- * shares its credits or did (`poolSharesCredits`). Without it, whether any
1899
- * page loaded for the workspace so far had a row another workspace spent:
1900
- * once shown it stays, on every page, until another workspace.
1899
+ * shares its credits or did (`poolSharesCredits`). Without it, or when the
1900
+ * pool could not be read (`failed`: a member who is not a workspace admin gets
1901
+ * a 403), whether any page loaded for the workspace so far had a row another
1902
+ * workspace spent: once shown it stays, on every page, until another workspace.
1901
1903
  */
1902
1904
  declare function usageLogsShowWorkspace(state: Pick<UsageLogsState, "spentByOthers">, pool: {
1903
1905
  hasCreditPool: boolean;
1904
1906
  sharesCredits: boolean;
1907
+ failed?: boolean;
1905
1908
  }): boolean;
1906
1909
  interface UsedByNamesLoader {
1907
1910
  /** Look up `workspaceId`'s names, unless they are saved or being looked up. */
@@ -1917,11 +1920,14 @@ interface UsedByNamesLoader {
1917
1920
  * workspaces that spent its shared credits, and the pool itself (whether it
1918
1921
  * shares them at all). `save` gets each answer and says whether it
1919
1922
  * kept it (false: that workspace is no longer shown); only a kept answer ends
1920
- * the lookups for that workspace. A failed or unkept lookup is tried again on
1921
- * the next call; a call while one for the same workspace is under way starts
1922
- * no other.
1923
- */
1924
- declare function createUsedByNamesLoader(save: (workspaceId: string, names: Record<string, string>, pool: CreditPoolResponse) => boolean): UsedByNamesLoader;
1923
+ * the lookups for that workspace. An unkept lookup is tried again on the next
1924
+ * call. A failed one calls `failed` (the Workspace column falls back to the
1925
+ * rows) and is tried once more on a later call when it was the network
1926
+ * (status 0 included) or a 5xx; a 4xx such as 401/403, or a second failure,
1927
+ * ends the lookups for that workspace until `reset`, so turning pages does not ask again. A call while
1928
+ * one for the same workspace is under way starts no other.
1929
+ */
1930
+ declare function createUsedByNamesLoader(save: (workspaceId: string, names: Record<string, string>, pool: CreditPoolResponse) => boolean, failed?: (workspaceId: string) => void): UsedByNamesLoader;
1925
1931
  /** The CSV file name for a picked day range, from its local calendar days. */
1926
1932
  declare function usageLogsExportFileName(start: Date, end: Date): string;
1927
1933
  /**
package/dist/index.js CHANGED
@@ -11554,23 +11554,39 @@ function usageLogsSpentByOthers(logs, workspaceId) {
11554
11554
  );
11555
11555
  }
11556
11556
  function usageLogsShowWorkspace(state, pool) {
11557
- return pool.hasCreditPool ? pool.sharesCredits : state.spentByOthers;
11557
+ return pool.hasCreditPool && !pool.failed ? pool.sharesCredits : state.spentByOthers;
11558
11558
  }
11559
- function createUsedByNamesLoader(save) {
11559
+ function creditPoolFailureRetryable(failure) {
11560
+ const error = failure;
11561
+ const status = [error?.status, error?.statusCode, error?.response?.status].find(
11562
+ (value) => typeof value === "number" && Number.isFinite(value) && value > 0
11563
+ );
11564
+ return status === void 0 || status < 400 || status >= 500;
11565
+ }
11566
+ function createUsedByNamesLoader(save, failed) {
11560
11567
  let savedFor = null;
11561
11568
  let inFlight = null;
11569
+ let failedFor = null;
11562
11570
  return {
11563
11571
  async load(workspaceId, fetchCreditPool) {
11564
11572
  if (savedFor === workspaceId || inFlight?.workspaceId === workspaceId) {
11565
11573
  return;
11566
11574
  }
11575
+ if (failedFor?.workspaceId === workspaceId && !failedFor.retry) return;
11567
11576
  const lookup = { workspaceId };
11568
11577
  inFlight = lookup;
11569
11578
  try {
11570
11579
  const pool = await fetchCreditPool();
11571
11580
  if (inFlight !== lookup) return;
11572
11581
  if (save(workspaceId, usedByNamesFrom(pool), pool)) savedFor = workspaceId;
11573
- } catch {
11582
+ } catch (failure) {
11583
+ if (inFlight !== lookup) return;
11584
+ const retried = failedFor?.workspaceId === workspaceId;
11585
+ failedFor = {
11586
+ workspaceId,
11587
+ retry: !retried && creditPoolFailureRetryable(failure)
11588
+ };
11589
+ failed?.(workspaceId);
11574
11590
  } finally {
11575
11591
  if (inFlight === lookup) inFlight = null;
11576
11592
  }
@@ -11578,6 +11594,7 @@ function createUsedByNamesLoader(save) {
11578
11594
  reset() {
11579
11595
  savedFor = null;
11580
11596
  inFlight = null;
11597
+ failedFor = null;
11581
11598
  }
11582
11599
  };
11583
11600
  }
@@ -12943,6 +12960,7 @@ function BillingContent({
12943
12960
  const [sponsorShare, setSponsorShare] = (0, import_react24.useState)(null);
12944
12961
  const [usedByNames, setUsedByNames] = (0, import_react24.useState)({});
12945
12962
  const [sharesCredits, setSharesCredits] = (0, import_react24.useState)(false);
12963
+ const [creditPoolFailed, setCreditPoolFailed] = (0, import_react24.useState)(false);
12946
12964
  const [allProducts, setProducts] = (0, import_react24.useState)([]);
12947
12965
  const workspaceCountry = workspace.current?.country;
12948
12966
  const products = (0, import_react24.useMemo)(
@@ -12966,12 +12984,18 @@ function BillingContent({
12966
12984
  const workspaceIdRef = (0, import_react24.useRef)(workspaceId);
12967
12985
  workspaceIdRef.current = workspaceId;
12968
12986
  const loadUsedByNamesRef = (0, import_react24.useRef)(null);
12969
- loadUsedByNamesRef.current ??= createUsedByNamesLoader((forWorkspace, names, pool) => {
12970
- if (forWorkspace !== workspaceIdRef.current) return false;
12971
- setUsedByNames(names);
12972
- setSharesCredits(poolSharesCredits(pool));
12973
- return true;
12974
- });
12987
+ loadUsedByNamesRef.current ??= createUsedByNamesLoader(
12988
+ (forWorkspace, names, pool) => {
12989
+ if (forWorkspace !== workspaceIdRef.current) return false;
12990
+ setUsedByNames(names);
12991
+ setSharesCredits(poolSharesCredits(pool));
12992
+ setCreditPoolFailed(false);
12993
+ return true;
12994
+ },
12995
+ (forWorkspace) => {
12996
+ if (forWorkspace === workspaceIdRef.current) setCreditPoolFailed(true);
12997
+ }
12998
+ );
12975
12999
  const [userMap, setUserMap] = (0, import_react24.useState)({});
12976
13000
  const [customPlanCredits, setCustomPlanCredits] = (0, import_react24.useState)(
12977
13001
  null
@@ -13254,6 +13278,7 @@ function BillingContent({
13254
13278
  loadUsedByNamesRef.current?.reset();
13255
13279
  setUsedByNames({});
13256
13280
  setSharesCredits(false);
13281
+ setCreditPoolFailed(false);
13257
13282
  }, [workspaceId]);
13258
13283
  (0, import_react24.useEffect)(() => {
13259
13284
  setInitialFetchTriggered(true);
@@ -13961,7 +13986,8 @@ function BillingContent({
13961
13986
  usedByNames,
13962
13987
  showWorkspace: usageLogsShowWorkspace(usageLogsState, {
13963
13988
  hasCreditPool: Boolean(api.fetchCreditPool),
13964
- sharesCredits
13989
+ sharesCredits,
13990
+ failed: creditPoolFailed
13965
13991
  })
13966
13992
  }
13967
13993
  ),
package/dist/index.mjs CHANGED
@@ -11429,23 +11429,39 @@ function usageLogsSpentByOthers(logs, workspaceId) {
11429
11429
  );
11430
11430
  }
11431
11431
  function usageLogsShowWorkspace(state, pool) {
11432
- return pool.hasCreditPool ? pool.sharesCredits : state.spentByOthers;
11432
+ return pool.hasCreditPool && !pool.failed ? pool.sharesCredits : state.spentByOthers;
11433
11433
  }
11434
- function createUsedByNamesLoader(save) {
11434
+ function creditPoolFailureRetryable(failure) {
11435
+ const error = failure;
11436
+ const status = [error?.status, error?.statusCode, error?.response?.status].find(
11437
+ (value) => typeof value === "number" && Number.isFinite(value) && value > 0
11438
+ );
11439
+ return status === void 0 || status < 400 || status >= 500;
11440
+ }
11441
+ function createUsedByNamesLoader(save, failed) {
11435
11442
  let savedFor = null;
11436
11443
  let inFlight = null;
11444
+ let failedFor = null;
11437
11445
  return {
11438
11446
  async load(workspaceId, fetchCreditPool) {
11439
11447
  if (savedFor === workspaceId || inFlight?.workspaceId === workspaceId) {
11440
11448
  return;
11441
11449
  }
11450
+ if (failedFor?.workspaceId === workspaceId && !failedFor.retry) return;
11442
11451
  const lookup = { workspaceId };
11443
11452
  inFlight = lookup;
11444
11453
  try {
11445
11454
  const pool = await fetchCreditPool();
11446
11455
  if (inFlight !== lookup) return;
11447
11456
  if (save(workspaceId, usedByNamesFrom(pool), pool)) savedFor = workspaceId;
11448
- } catch {
11457
+ } catch (failure) {
11458
+ if (inFlight !== lookup) return;
11459
+ const retried = failedFor?.workspaceId === workspaceId;
11460
+ failedFor = {
11461
+ workspaceId,
11462
+ retry: !retried && creditPoolFailureRetryable(failure)
11463
+ };
11464
+ failed?.(workspaceId);
11449
11465
  } finally {
11450
11466
  if (inFlight === lookup) inFlight = null;
11451
11467
  }
@@ -11453,6 +11469,7 @@ function createUsedByNamesLoader(save) {
11453
11469
  reset() {
11454
11470
  savedFor = null;
11455
11471
  inFlight = null;
11472
+ failedFor = null;
11456
11473
  }
11457
11474
  };
11458
11475
  }
@@ -12818,6 +12835,7 @@ function BillingContent({
12818
12835
  const [sponsorShare, setSponsorShare] = useState22(null);
12819
12836
  const [usedByNames, setUsedByNames] = useState22({});
12820
12837
  const [sharesCredits, setSharesCredits] = useState22(false);
12838
+ const [creditPoolFailed, setCreditPoolFailed] = useState22(false);
12821
12839
  const [allProducts, setProducts] = useState22([]);
12822
12840
  const workspaceCountry = workspace.current?.country;
12823
12841
  const products = useMemo4(
@@ -12841,12 +12859,18 @@ function BillingContent({
12841
12859
  const workspaceIdRef = useRef12(workspaceId);
12842
12860
  workspaceIdRef.current = workspaceId;
12843
12861
  const loadUsedByNamesRef = useRef12(null);
12844
- loadUsedByNamesRef.current ??= createUsedByNamesLoader((forWorkspace, names, pool) => {
12845
- if (forWorkspace !== workspaceIdRef.current) return false;
12846
- setUsedByNames(names);
12847
- setSharesCredits(poolSharesCredits(pool));
12848
- return true;
12849
- });
12862
+ loadUsedByNamesRef.current ??= createUsedByNamesLoader(
12863
+ (forWorkspace, names, pool) => {
12864
+ if (forWorkspace !== workspaceIdRef.current) return false;
12865
+ setUsedByNames(names);
12866
+ setSharesCredits(poolSharesCredits(pool));
12867
+ setCreditPoolFailed(false);
12868
+ return true;
12869
+ },
12870
+ (forWorkspace) => {
12871
+ if (forWorkspace === workspaceIdRef.current) setCreditPoolFailed(true);
12872
+ }
12873
+ );
12850
12874
  const [userMap, setUserMap] = useState22({});
12851
12875
  const [customPlanCredits, setCustomPlanCredits] = useState22(
12852
12876
  null
@@ -13129,6 +13153,7 @@ function BillingContent({
13129
13153
  loadUsedByNamesRef.current?.reset();
13130
13154
  setUsedByNames({});
13131
13155
  setSharesCredits(false);
13156
+ setCreditPoolFailed(false);
13132
13157
  }, [workspaceId]);
13133
13158
  useEffect19(() => {
13134
13159
  setInitialFetchTriggered(true);
@@ -13836,7 +13861,8 @@ function BillingContent({
13836
13861
  usedByNames,
13837
13862
  showWorkspace: usageLogsShowWorkspace(usageLogsState, {
13838
13863
  hasCreditPool: Boolean(api.fetchCreditPool),
13839
- sharesCredits
13864
+ sharesCredits,
13865
+ failed: creditPoolFailed
13840
13866
  })
13841
13867
  }
13842
13868
  ),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamoid/settings",
3
- "version": "0.22.3",
3
+ "version": "0.22.4",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",