@hexclave/shared 1.0.23 → 1.0.24

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.
Files changed (79) hide show
  1. package/dist/ai/unified-prompts/reminders.js +2 -1
  2. package/dist/ai/unified-prompts/reminders.js.map +1 -1
  3. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.d.ts.map +1 -1
  4. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js +15 -0
  5. package/dist/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js.map +1 -1
  6. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.d.ts +1 -46
  7. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js +1 -62
  8. package/dist/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js.map +1 -1
  9. package/dist/config/schema.d.ts +74 -74
  10. package/dist/esm/ai/unified-prompts/reminders.js +2 -1
  11. package/dist/esm/ai/unified-prompts/reminders.js.map +1 -1
  12. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.d.ts.map +1 -1
  13. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js +15 -0
  14. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.js.map +1 -1
  15. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.d.ts +1 -46
  16. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js +1 -62
  17. package/dist/esm/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.js.map +1 -1
  18. package/dist/esm/config/schema.d.ts +74 -74
  19. package/dist/esm/interface/admin-metrics.d.ts +14 -14
  20. package/dist/esm/interface/conversations.d.ts +11 -11
  21. package/dist/esm/interface/crud/current-user.d.ts +11 -11
  22. package/dist/esm/interface/crud/email-outbox.d.ts +136 -136
  23. package/dist/esm/interface/crud/invoices.d.ts +2 -2
  24. package/dist/esm/interface/crud/products.d.ts +15 -15
  25. package/dist/esm/interface/crud/products.d.ts.map +1 -1
  26. package/dist/esm/interface/crud/project-api-keys.d.ts +4 -4
  27. package/dist/esm/interface/crud/projects.d.ts +36 -36
  28. package/dist/esm/interface/crud/team-member-profiles.d.ts +36 -36
  29. package/dist/esm/interface/crud/transactions.d.ts +21 -21
  30. package/dist/esm/interface/crud/transactions.d.ts.map +1 -1
  31. package/dist/esm/interface/crud/users.d.ts +18 -18
  32. package/dist/esm/interface/webhooks.d.ts +2 -2
  33. package/dist/esm/known-errors.d.ts +5 -5
  34. package/dist/esm/schema-fields.d.ts +5 -5
  35. package/dist/esm/sessions.d.ts +7 -7
  36. package/dist/esm/utils/env.d.ts +2 -1
  37. package/dist/esm/utils/env.d.ts.map +1 -1
  38. package/dist/esm/utils/env.js +29 -17
  39. package/dist/esm/utils/env.js.map +1 -1
  40. package/dist/esm/utils/env.test.d.ts +1 -0
  41. package/dist/esm/utils/env.test.js +49 -0
  42. package/dist/esm/utils/env.test.js.map +1 -0
  43. package/dist/esm/utils/errors.d.ts.map +1 -1
  44. package/dist/esm/utils/errors.js +4 -1
  45. package/dist/esm/utils/errors.js.map +1 -1
  46. package/dist/interface/admin-metrics.d.ts +14 -14
  47. package/dist/interface/conversations.d.ts +11 -11
  48. package/dist/interface/crud/current-user.d.ts +11 -11
  49. package/dist/interface/crud/email-outbox.d.ts +136 -136
  50. package/dist/interface/crud/invoices.d.ts +2 -2
  51. package/dist/interface/crud/products.d.ts +15 -15
  52. package/dist/interface/crud/products.d.ts.map +1 -1
  53. package/dist/interface/crud/project-api-keys.d.ts +4 -4
  54. package/dist/interface/crud/projects.d.ts +36 -36
  55. package/dist/interface/crud/team-member-profiles.d.ts +36 -36
  56. package/dist/interface/crud/transactions.d.ts +21 -21
  57. package/dist/interface/crud/transactions.d.ts.map +1 -1
  58. package/dist/interface/crud/users.d.ts +18 -18
  59. package/dist/interface/webhooks.d.ts +2 -2
  60. package/dist/known-errors.d.ts +5 -5
  61. package/dist/schema-fields.d.ts +5 -5
  62. package/dist/sessions.d.ts +7 -7
  63. package/dist/utils/env.d.ts +2 -1
  64. package/dist/utils/env.d.ts.map +1 -1
  65. package/dist/utils/env.js +29 -16
  66. package/dist/utils/env.js.map +1 -1
  67. package/dist/utils/env.test.d.ts +1 -0
  68. package/dist/utils/env.test.js +49 -0
  69. package/dist/utils/env.test.js.map +1 -0
  70. package/dist/utils/errors.d.ts.map +1 -1
  71. package/dist/utils/errors.js +4 -1
  72. package/dist/utils/errors.js.map +1 -1
  73. package/package.json +1 -1
  74. package/src/ai/unified-prompts/reminders.ts +1 -0
  75. package/src/ai/unified-prompts/skill-site-prompt-parts/ai-setup-prompt.ts +15 -0
  76. package/src/ai/unified-prompts/skill-site-prompt-parts/docs-json.generated.ts +1 -62
  77. package/src/utils/env.test.tsx +58 -0
  78. package/src/utils/env.tsx +36 -20
  79. package/src/utils/errors.tsx +6 -1
@@ -83,8 +83,8 @@ declare const usersCrudServerReadSchema: yup$1.ObjectSchema<{
83
83
  server_metadata?: {} | null | undefined;
84
84
  display_name: string;
85
85
  id: string;
86
- created_at_millis: number;
87
86
  profile_image_url: string | null;
87
+ created_at_millis: number;
88
88
  } | null;
89
89
  selected_team_id: string | null;
90
90
  profile_image_url: string | null;
@@ -163,18 +163,20 @@ declare const usersCrudServerReadSchema: yup$1.ObjectSchema<{
163
163
  requires_totp_mfa: undefined;
164
164
  }, "">;
165
165
  declare const usersCrudServerCreateSchema: yup$1.ObjectSchema<{
166
- primary_email: string | null | undefined;
167
166
  display_name: string | null | undefined;
168
167
  client_metadata: {} | null | undefined;
169
168
  client_read_only_metadata: {} | null | undefined;
170
169
  server_metadata: {} | null | undefined;
171
170
  is_anonymous: boolean | undefined;
172
- password: string | null | undefined;
171
+ primary_email: string | null | undefined;
172
+ profile_image_url: string | null | undefined;
173
173
  primary_email_verified: boolean | undefined;
174
174
  primary_email_auth_enabled: boolean | undefined;
175
- profile_image_url: string | null | undefined;
176
- otp_auth_enabled: boolean | undefined;
177
175
  passkey_auth_enabled: boolean | undefined;
176
+ password: string | null | undefined;
177
+ password_hash: string | undefined;
178
+ otp_auth_enabled: boolean | undefined;
179
+ totp_secret_base64: string | null | undefined;
178
180
  restricted_by_admin: boolean | undefined;
179
181
  restricted_by_admin_reason: string | null | undefined;
180
182
  restricted_by_admin_private_details: string | null | undefined;
@@ -185,12 +187,10 @@ declare const usersCrudServerCreateSchema: yup$1.ObjectSchema<{
185
187
  free_trial_abuse: number;
186
188
  };
187
189
  } | undefined;
188
- password_hash: string | undefined;
189
- totp_secret_base64: string | null | undefined;
190
190
  } & {
191
191
  oauth_providers: {
192
- email: string | null;
193
192
  id: string;
193
+ email: string | null;
194
194
  account_id: string;
195
195
  }[] | undefined;
196
196
  is_anonymous: boolean | undefined;
@@ -236,8 +236,8 @@ declare const usersCrud: ______crud0.CrudSchemaFromOptions<{
236
236
  server_metadata?: {} | null | undefined;
237
237
  display_name: string;
238
238
  id: string;
239
- created_at_millis: number;
240
239
  profile_image_url: string | null;
240
+ created_at_millis: number;
241
241
  } | null;
242
242
  selected_team_id: string | null;
243
243
  profile_image_url: string | null;
@@ -369,18 +369,20 @@ declare const usersCrud: ______crud0.CrudSchemaFromOptions<{
369
369
  };
370
370
  }, "">;
371
371
  serverCreateSchema: yup$1.ObjectSchema<{
372
- primary_email: string | null | undefined;
373
372
  display_name: string | null | undefined;
374
373
  client_metadata: {} | null | undefined;
375
374
  client_read_only_metadata: {} | null | undefined;
376
375
  server_metadata: {} | null | undefined;
377
376
  is_anonymous: boolean | undefined;
378
- password: string | null | undefined;
377
+ primary_email: string | null | undefined;
378
+ profile_image_url: string | null | undefined;
379
379
  primary_email_verified: boolean | undefined;
380
380
  primary_email_auth_enabled: boolean | undefined;
381
- profile_image_url: string | null | undefined;
382
- otp_auth_enabled: boolean | undefined;
383
381
  passkey_auth_enabled: boolean | undefined;
382
+ password: string | null | undefined;
383
+ password_hash: string | undefined;
384
+ otp_auth_enabled: boolean | undefined;
385
+ totp_secret_base64: string | null | undefined;
384
386
  restricted_by_admin: boolean | undefined;
385
387
  restricted_by_admin_reason: string | null | undefined;
386
388
  restricted_by_admin_private_details: string | null | undefined;
@@ -391,12 +393,10 @@ declare const usersCrud: ______crud0.CrudSchemaFromOptions<{
391
393
  free_trial_abuse: number;
392
394
  };
393
395
  } | undefined;
394
- password_hash: string | undefined;
395
- totp_secret_base64: string | null | undefined;
396
396
  } & {
397
397
  oauth_providers: {
398
- email: string | null;
399
398
  id: string;
399
+ email: string | null;
400
400
  account_id: string;
401
401
  }[] | undefined;
402
402
  is_anonymous: boolean | undefined;
@@ -470,8 +470,8 @@ declare const userCreatedWebhookEvent: WebhookEvent<yup$1.ObjectSchema<{
470
470
  server_metadata?: {} | null | undefined;
471
471
  display_name: string;
472
472
  id: string;
473
- created_at_millis: number;
474
473
  profile_image_url: string | null;
474
+ created_at_millis: number;
475
475
  } | null;
476
476
  selected_team_id: string | null;
477
477
  profile_image_url: string | null;
@@ -561,8 +561,8 @@ declare const userUpdatedWebhookEvent: WebhookEvent<yup$1.ObjectSchema<{
561
561
  server_metadata?: {} | null | undefined;
562
562
  display_name: string;
563
563
  id: string;
564
- created_at_millis: number;
565
564
  profile_image_url: string | null;
565
+ created_at_millis: number;
566
566
  } | null;
567
567
  selected_team_id: string | null;
568
568
  profile_image_url: string | null;
@@ -22,8 +22,8 @@ declare const webhookEvents: readonly [WebhookEvent<yup$1.ObjectSchema<{
22
22
  server_metadata?: {} | null | undefined;
23
23
  display_name: string;
24
24
  id: string;
25
- created_at_millis: number;
26
25
  profile_image_url: string | null;
26
+ created_at_millis: number;
27
27
  } | null;
28
28
  selected_team_id: string | null;
29
29
  profile_image_url: string | null;
@@ -112,8 +112,8 @@ declare const webhookEvents: readonly [WebhookEvent<yup$1.ObjectSchema<{
112
112
  server_metadata?: {} | null | undefined;
113
113
  display_name: string;
114
114
  id: string;
115
- created_at_millis: number;
116
115
  profile_image_url: string | null;
116
+ created_at_millis: number;
117
117
  } | null;
118
118
  selected_team_id: string | null;
119
119
  profile_image_url: string | null;
@@ -369,7 +369,7 @@ declare const KnownErrors: {
369
369
  PermissionNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"PERMISSION_NOT_FOUND">, [permissionId: string]> & {
370
370
  errorCode: "PERMISSION_NOT_FOUND";
371
371
  };
372
- PermissionScopeMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"WRONG_PERMISSION_SCOPE">, [permissionId: string, expectedScope: "team" | "project", actualScope: "team" | "project" | null]> & {
372
+ PermissionScopeMismatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"WRONG_PERMISSION_SCOPE">, [permissionId: string, expectedScope: "project" | "team", actualScope: "project" | "team" | null]> & {
373
373
  errorCode: "WRONG_PERMISSION_SCOPE";
374
374
  };
375
375
  ContainedPermissionNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"CONTAINED_PERMISSION_NOT_FOUND">, [permissionId: string]> & {
@@ -512,16 +512,16 @@ declare const KnownErrors: {
512
512
  ItemNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"ITEM_NOT_FOUND">, [itemId: string]> & {
513
513
  errorCode: "ITEM_NOT_FOUND";
514
514
  };
515
- ItemCustomerTypeDoesNotMatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"ITEM_CUSTOMER_TYPE_DOES_NOT_MATCH">, [itemId: string, customerId: string, itemCustomerType: "team" | "user" | "custom" | undefined, actualCustomerType: "team" | "user" | "custom"]> & {
515
+ ItemCustomerTypeDoesNotMatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"ITEM_CUSTOMER_TYPE_DOES_NOT_MATCH">, [itemId: string, customerId: string, itemCustomerType: "user" | "team" | "custom" | undefined, actualCustomerType: "user" | "team" | "custom"]> & {
516
516
  errorCode: "ITEM_CUSTOMER_TYPE_DOES_NOT_MATCH";
517
517
  };
518
518
  CustomerDoesNotExist: KnownErrorConstructor<KnownError & KnownErrorBrand<"CUSTOMER_DOES_NOT_EXIST">, [customerId: string]> & {
519
519
  errorCode: "CUSTOMER_DOES_NOT_EXIST";
520
520
  };
521
- ProductDoesNotExist: KnownErrorConstructor<KnownError & KnownErrorBrand<"PRODUCT_DOES_NOT_EXIST">, [productId: string, context: "item_exists" | "server_only" | null]> & {
521
+ ProductDoesNotExist: KnownErrorConstructor<KnownError & KnownErrorBrand<"PRODUCT_DOES_NOT_EXIST">, [productId: string, context: "server_only" | "item_exists" | null]> & {
522
522
  errorCode: "PRODUCT_DOES_NOT_EXIST";
523
523
  };
524
- ProductCustomerTypeDoesNotMatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"PRODUCT_CUSTOMER_TYPE_DOES_NOT_MATCH">, [productId: string | undefined, customerId: string, productCustomerType: "team" | "user" | "custom" | undefined, actualCustomerType: "team" | "user" | "custom"]> & {
524
+ ProductCustomerTypeDoesNotMatch: KnownErrorConstructor<KnownError & KnownErrorBrand<"PRODUCT_CUSTOMER_TYPE_DOES_NOT_MATCH">, [productId: string | undefined, customerId: string, productCustomerType: "user" | "team" | "custom" | undefined, actualCustomerType: "user" | "team" | "custom"]> & {
525
525
  errorCode: "PRODUCT_CUSTOMER_TYPE_DOES_NOT_MATCH";
526
526
  };
527
527
  ProductAlreadyGranted: KnownErrorConstructor<KnownError & KnownErrorBrand<"PRODUCT_ALREADY_GRANTED">, [productId: string, customerId: string]> & {
@@ -548,7 +548,7 @@ declare const KnownErrors: {
548
548
  StripeAccountInfoNotFound: KnownErrorConstructor<KnownError & KnownErrorBrand<"STRIPE_ACCOUNT_INFO_NOT_FOUND">, []> & {
549
549
  errorCode: "STRIPE_ACCOUNT_INFO_NOT_FOUND";
550
550
  };
551
- DefaultPaymentMethodRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"DEFAULT_PAYMENT_METHOD_REQUIRED">, [customerType: "team" | "user", customerId: string]> & {
551
+ DefaultPaymentMethodRequired: KnownErrorConstructor<KnownError & KnownErrorBrand<"DEFAULT_PAYMENT_METHOD_REQUIRED">, [customerType: "user" | "team", customerId: string]> & {
552
552
  errorCode: "DEFAULT_PAYMENT_METHOD_REQUIRED";
553
553
  };
554
554
  NewPurchasesBlocked: KnownErrorConstructor<KnownError & KnownErrorBrand<"NEW_PURCHASES_BLOCKED">, []> & {
@@ -174,7 +174,7 @@ declare const customDashboardsSchema: yup$1.MixedSchema<Record<string, {
174
174
  displayName: string;
175
175
  tsxSource: string;
176
176
  }>, yup$1.AnyObject, undefined, "">;
177
- declare const customerTypeSchema: yup$1.StringSchema<"team" | "user" | "custom" | undefined, yup$1.AnyObject, undefined, "">;
177
+ declare const customerTypeSchema: yup$1.StringSchema<"user" | "team" | "custom" | undefined, yup$1.AnyObject, undefined, "">;
178
178
  /**
179
179
  * Schema for a single product price. Each currency field (USD, EUR, etc.) is a decimal string
180
180
  * like `"9.99"` or `"1000"` — never cent integers. See `MoneyAmount` for the exact format.
@@ -218,7 +218,7 @@ declare const productSchema: yup$1.ObjectSchema<{
218
218
  displayName: string | undefined;
219
219
  productLineId: string | undefined;
220
220
  isAddOnTo: false | Record<string, true> | undefined;
221
- customerType: "team" | "user" | "custom";
221
+ customerType: "user" | "team" | "custom";
222
222
  freeTrial: DayInterval | undefined;
223
223
  serverOnly: boolean | undefined;
224
224
  stackable: boolean | undefined;
@@ -257,7 +257,7 @@ declare const productSchemaWithMetadata: yup$1.ObjectSchema<{
257
257
  displayName: string | undefined;
258
258
  productLineId: string | undefined;
259
259
  isAddOnTo: false | Record<string, true> | undefined;
260
- customerType: "team" | "user" | "custom";
260
+ customerType: "user" | "team" | "custom";
261
261
  freeTrial: DayInterval | undefined;
262
262
  serverOnly: boolean | undefined;
263
263
  stackable: boolean | undefined;
@@ -298,7 +298,7 @@ declare const productSchemaWithMetadata: yup$1.ObjectSchema<{
298
298
  }, "">;
299
299
  declare const inlineProductSchema: yup$1.ObjectSchema<{
300
300
  display_name: string;
301
- customer_type: "team" | "user" | "custom";
301
+ customer_type: "user" | "team" | "custom";
302
302
  free_trial: DayInterval | undefined;
303
303
  server_only: boolean;
304
304
  stackable: boolean;
@@ -314,8 +314,8 @@ declare const inlineProductSchema: yup$1.ObjectSchema<{
314
314
  free_trial?: DayInterval | undefined;
315
315
  }>;
316
316
  included_items: Record<string, {
317
- quantity?: number | undefined;
318
317
  repeat?: "never" | DayInterval | undefined;
318
+ quantity?: number | undefined;
319
319
  expires?: "never" | "when-purchase-expires" | "when-repeated" | undefined;
320
320
  }>;
321
321
  client_metadata: {} | null | undefined;
@@ -9,24 +9,24 @@ declare class AccessToken {
9
9
  private constructor();
10
10
  get payload(): {
11
11
  exp?: number | undefined;
12
- project_id: string;
13
- refresh_token_id: string;
14
- email: string | null;
15
- restricted_reason: {
16
- type: "anonymous" | "email_not_verified" | "restricted_by_administrator";
17
- } | null;
18
- branch_id: string;
19
12
  sub: string;
20
13
  iat: number;
21
14
  iss: string;
22
15
  aud: string;
16
+ project_id: string;
17
+ branch_id: string;
18
+ refresh_token_id: string;
23
19
  role: "authenticated";
24
20
  name: string | null;
21
+ email: string | null;
25
22
  email_verified: boolean;
26
23
  selected_team_id: string | null;
27
24
  signed_up_at: number;
28
25
  is_anonymous: boolean;
29
26
  is_restricted: boolean;
27
+ restricted_reason: {
28
+ type: "anonymous" | "email_not_verified" | "restricted_by_administrator";
29
+ } | null;
30
30
  requires_totp_mfa: boolean;
31
31
  };
32
32
  get expiresAt(): Date;
@@ -1,5 +1,6 @@
1
1
  //#region src/utils/env.d.ts
2
2
  declare function isBrowserLike(): boolean;
3
+ declare function resolveHexclaveStackEnvVarValue(hexclaveName: string, stackName: string, hexclaveValue: string | undefined, stackValue: string | undefined): string | undefined;
3
4
  /**
4
5
  * Returns the environment variable with the given name, returning the default (if given) or throwing an error (otherwise) if it's undefined or the empty string.
5
6
  */
@@ -21,5 +22,5 @@ declare function getNodeEnvironment(): string;
21
22
  */
22
23
  declare function getProcessEnv(name: string): string | undefined;
23
24
  //#endregion
24
- export { getEnvBoolean, getEnvVariable, getNextRuntime, getNodeEnvironment, getProcessEnv, isBrowserLike };
25
+ export { getEnvBoolean, getEnvVariable, getNextRuntime, getNodeEnvironment, getProcessEnv, isBrowserLike, resolveHexclaveStackEnvVarValue };
25
26
  //# sourceMappingURL=env.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/utils/env.tsx"],"mappings":";iBAGgB,aAAA,CAAA;AAAhB;;;AAAA,iBA0BgB,cAAA,CAAe,IAAA,UAAc,YAAA;AAAA,iBAgD7B,aAAA,CAAc,IAAA;AAAA,iBAWd,cAAA,CAAA;AAAA,iBAKA,kBAAA,CAAA;;;;AAhBhB;;;;;AAWA;;;;iBAqBgB,aAAA,CAAc,IAAA"}
1
+ {"version":3,"file":"env.d.ts","names":[],"sources":["../../../src/utils/env.tsx"],"mappings":";iBAGgB,aAAA,CAAA;AAAA,iBASA,+BAAA,CAAgC,YAAA,UAAsB,SAAA,UAAmB,aAAA,sBAAmC,UAAA;;;;iBAgC5G,cAAA,CAAe,IAAA,UAAc,YAAA;AAAA,iBAgD7B,aAAA,CAAc,IAAA;AAAA,iBAWd,cAAA,CAAA;AAAA,iBAKA,kBAAA,CAAA;;;;;;;;AAhEhB;;;;;iBAgFgB,aAAA,CAAc,IAAA"}
@@ -6,16 +6,30 @@ function isBrowserLike() {
6
6
  return typeof window !== "undefined" && typeof document !== "undefined" && typeof document.createElement !== "undefined";
7
7
  }
8
8
  const ENV_VAR_RENAME = { NEXT_PUBLIC_STACK_API_URL: ["STACK_BASE_URL", "NEXT_PUBLIC_STACK_URL"] };
9
+ function resolveHexclaveStackEnvVarValue(hexclaveName, stackName, hexclaveValue, stackValue) {
10
+ if (hexclaveValue && stackValue && hexclaveValue !== stackValue) throw new Error(`Environment variables ${hexclaveName} and ${stackName} are both set to different values. Remove one of them or set them to the same value.`);
11
+ return hexclaveValue || stackValue || void 0;
12
+ }
9
13
  /**
10
- * Hexclave rebrand: compute the `HEXCLAVE_*`-prefixed equivalent of a `STACK_*`
11
- * env var name by replacing the first `STACK_` occurrence with `HEXCLAVE_`.
12
- * Covers `STACK_FOO`, `NEXT_PUBLIC_STACK_FOO`, `NEXT_PUBLIC_BROWSER_STACK_FOO`,
13
- * `NEXT_PUBLIC_SERVER_STACK_FOO`, `VITE_STACK_FOO`. Returns `undefined` when the
14
- * name has no `STACK_` segment (caller should behave exactly as before).
14
+ * Hexclave rebrand: resolve an env var by reading both the `HEXCLAVE_*` and
15
+ * `STACK_*` spellings, preferring the canonical Hexclave value and falling back
16
+ * to the legacy Stack value (empty counts as unset). Works in BOTH directions —
17
+ * whether the caller passes the legacy `STACK_FOO` name or the canonical
18
+ * `HEXCLAVE_FOO` name, the other spelling is still honored. Covers `STACK_FOO`,
19
+ * `NEXT_PUBLIC_STACK_FOO`, `NEXT_PUBLIC_BROWSER_STACK_FOO`,
20
+ * `NEXT_PUBLIC_SERVER_STACK_FOO`, `VITE_STACK_FOO` and their HEXCLAVE_ twins.
21
+ * Names with neither segment behave exactly as before.
15
22
  */
16
- function getHexclaveEnvVarName(name) {
17
- if (!name.includes("STACK_")) return;
18
- return name.replace("STACK_", "HEXCLAVE_");
23
+ function getEnvVarWithHexclaveFallback(name) {
24
+ if (name.includes("STACK_")) {
25
+ const hexclaveName = name.replace("STACK_", "HEXCLAVE_");
26
+ return resolveHexclaveStackEnvVarValue(hexclaveName, name, process.env[hexclaveName], process.env[name]);
27
+ }
28
+ if (name.includes("HEXCLAVE_")) {
29
+ const stackName = name.replace("HEXCLAVE_", "STACK_");
30
+ return resolveHexclaveStackEnvVarValue(name, stackName, process.env[name], process.env[stackName]);
31
+ }
32
+ return process.env[name];
19
33
  }
20
34
  /**
21
35
  * Returns the environment variable with the given name, returning the default (if given) or throwing an error (otherwise) if it's undefined or the empty string.
@@ -31,12 +45,11 @@ function getEnvVariable(name, defaultValue) {
31
45
 
32
46
  Use getNextRuntime() instead.
33
47
  `);
34
- for (const [newName, oldNames] of Object.entries(ENV_VAR_RENAME)) if (oldNames.includes(name)) throwErr(`Environment variable ${name} has been renamed to ${newName}. Please update your configuration to use the new name.`);
35
- const hexclaveName = getHexclaveEnvVarName(name);
36
- let value = (hexclaveName ? process.env[hexclaveName] : void 0) ?? process.env[name];
37
- if (!value && ENV_VAR_RENAME[name]) for (const oldName of ENV_VAR_RENAME[name]) {
38
- const hexclaveOldName = getHexclaveEnvVarName(oldName);
39
- value = (hexclaveOldName ? process.env[hexclaveOldName] : void 0) ?? process.env[oldName];
48
+ for (const [newName, oldNames] of Object.entries(ENV_VAR_RENAME)) if (oldNames?.includes(name)) throwErr(`Environment variable ${name} has been renamed to ${newName}. Please update your configuration to use the new name.`);
49
+ let value = getEnvVarWithHexclaveFallback(name);
50
+ const renamedNames = ENV_VAR_RENAME[name];
51
+ if (!value && renamedNames != null) for (const oldName of renamedNames) {
52
+ value = getEnvVarWithHexclaveFallback(oldName);
40
53
  if (value) break;
41
54
  }
42
55
  if (!value) if (defaultValue !== void 0) value = defaultValue;
@@ -69,10 +82,9 @@ function getNodeEnvironment() {
69
82
  */
70
83
  function getProcessEnv(name) {
71
84
  if (typeof process === "undefined" || typeof process.env === "undefined") return;
72
- const hexclaveName = getHexclaveEnvVarName(name);
73
- return (hexclaveName ? process.env[hexclaveName] : void 0) ?? process.env[name];
85
+ return getEnvVarWithHexclaveFallback(name);
74
86
  }
75
87
 
76
88
  //#endregion
77
- export { getEnvBoolean, getEnvVariable, getNextRuntime, getNodeEnvironment, getProcessEnv, isBrowserLike };
89
+ export { getEnvBoolean, getEnvVariable, getNextRuntime, getNodeEnvironment, getProcessEnv, isBrowserLike, resolveHexclaveStackEnvVarValue };
78
90
  //# sourceMappingURL=env.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"env.js","names":[],"sources":["../../../src/utils/env.tsx"],"sourcesContent":["import { HexclaveAssertionError, throwErr } from \"./errors\";\nimport { deindent } from \"./strings\";\n\nexport function isBrowserLike() {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\" && typeof document.createElement !== \"undefined\";\n}\n\n// newName: oldName\nconst ENV_VAR_RENAME: Record<string, string[]> = {\n NEXT_PUBLIC_STACK_API_URL: ['STACK_BASE_URL', 'NEXT_PUBLIC_STACK_URL'],\n};\n\n/**\n * Hexclave rebrand: compute the `HEXCLAVE_*`-prefixed equivalent of a `STACK_*`\n * env var name by replacing the first `STACK_` occurrence with `HEXCLAVE_`.\n * Covers `STACK_FOO`, `NEXT_PUBLIC_STACK_FOO`, `NEXT_PUBLIC_BROWSER_STACK_FOO`,\n * `NEXT_PUBLIC_SERVER_STACK_FOO`, `VITE_STACK_FOO`. Returns `undefined` when the\n * name has no `STACK_` segment (caller should behave exactly as before).\n */\nfunction getHexclaveEnvVarName(name: string): string | undefined {\n if (!name.includes(\"STACK_\")) {\n return undefined;\n }\n return name.replace(\"STACK_\", \"HEXCLAVE_\");\n}\n\n/**\n * Returns the environment variable with the given name, returning the default (if given) or throwing an error (otherwise) if it's undefined or the empty string.\n */\nexport function getEnvVariable(name: string, defaultValue?: string | undefined): string {\n if (isBrowserLike()) {\n throw new Error(deindent`\n Can't use getEnvVariable on the client because Next.js transpiles expressions of the kind process.env.XYZ at build-time on the client.\n \n Use process.env.XYZ directly instead.\n `);\n }\n if (name === \"NEXT_RUNTIME\") {\n throw new Error(deindent`\n Can't use getEnvVariable to access the NEXT_RUNTIME environment variable because it's compiled into the client bundle.\n \n Use getNextRuntime() instead.\n `);\n }\n\n // throw error if the old name is used as the retrieve key\n for (const [newName, oldNames] of Object.entries(ENV_VAR_RENAME)) {\n if (oldNames.includes(name)) {\n throwErr(`Environment variable ${name} has been renamed to ${newName}. Please update your configuration to use the new name.`);\n }\n }\n\n // Hexclave rebrand: prefer the HEXCLAVE_*-prefixed equivalent, fall back to the STACK_* name.\n const hexclaveName = getHexclaveEnvVarName(name);\n let value = (hexclaveName ? process.env[hexclaveName] : undefined) ?? process.env[name];\n\n // check the key under the old name if the new name is not found\n if (!value && ENV_VAR_RENAME[name] as any) {\n for (const oldName of ENV_VAR_RENAME[name]) {\n // Hexclave rebrand: also accept the HEXCLAVE_*-prefixed equivalent of each old alias.\n const hexclaveOldName = getHexclaveEnvVarName(oldName);\n value = (hexclaveOldName ? process.env[hexclaveOldName] : undefined) ?? process.env[oldName];\n if (value) break;\n }\n }\n\n if (!value) {\n if (defaultValue !== undefined) {\n value = defaultValue;\n } else {\n throwErr(`Missing environment variable: ${name}`);\n }\n }\n\n return value;\n}\n\nexport function getEnvBoolean(name: string): boolean {\n const value = getEnvVariable(name, \"false\");\n if (value === \"true\") {\n return true;\n } else if (value === \"false\") {\n return false;\n } else {\n throw new HexclaveAssertionError(`Environment variable ${name} must be either \"true\" or \"false\": found ${JSON.stringify(value)}`);\n }\n}\n\nexport function getNextRuntime() {\n // This variable is compiled into the client bundle, so we can't use getEnvVariable here.\n return process.env.NEXT_RUNTIME || throwErr(\"Missing environment variable: NEXT_RUNTIME\");\n}\n\nexport function getNodeEnvironment() {\n return getEnvVariable(\"NODE_ENV\", \"\");\n}\n\n/**\n * Browser-safe access to `process.env` for server-only or genuinely dynamic\n * env-var lookups. Returns `undefined` when `process` is not defined (e.g. in\n * a Vite browser bundle without a `process` shim).\n *\n * Note: uses `process.env[name]` (bracket form), which is NOT recognized by\n * Next.js / webpack DefinePlugin for compile-time inlining. If you need\n * build-time inlining for a `NEXT_PUBLIC_*` var, use the literal dot-form at\n * the call site, guarded with `typeof process`:\n *\n * const value = (typeof process !== \"undefined\" ? process.env.NEXT_PUBLIC_FOO : undefined);\n */\nexport function getProcessEnv(name: string): string | undefined {\n if (typeof process === \"undefined\" || typeof process.env === \"undefined\") {\n return undefined;\n }\n // Hexclave rebrand: prefer the HEXCLAVE_*-prefixed equivalent, fall back to the STACK_* name.\n const hexclaveName = getHexclaveEnvVarName(name);\n return (hexclaveName ? process.env[hexclaveName] : undefined) ?? process.env[name];\n}\n"],"mappings":";;;;AAGA,SAAgB,gBAAgB;AAC9B,QAAO,OAAO,WAAW,eAAe,OAAO,aAAa,eAAe,OAAO,SAAS,kBAAkB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AAO,YAAY,eAAe,OAAO,QAAQ,QAAQ,YAC3D;CAGF,MAAM,eAAe,sBAAsB,KAAK;AAChD,SAAQ,eAAe,QAAQ,IAAI,gBAAgB,WAAc,QAAQ,IAAI"}
1
+ {"version":3,"file":"env.js","names":[],"sources":["../../../src/utils/env.tsx"],"sourcesContent":["import { HexclaveAssertionError, throwErr } from \"./errors\";\nimport { deindent } from \"./strings\";\n\nexport function isBrowserLike() {\n return typeof window !== \"undefined\" && typeof document !== \"undefined\" && typeof document.createElement !== \"undefined\";\n}\n\n// newName: oldName\nconst ENV_VAR_RENAME: Record<string, string[] | undefined> = {\n NEXT_PUBLIC_STACK_API_URL: ['STACK_BASE_URL', 'NEXT_PUBLIC_STACK_URL'],\n};\n\nexport function resolveHexclaveStackEnvVarValue(hexclaveName: string, stackName: string, hexclaveValue: string | undefined, stackValue: string | undefined): string | undefined {\n if (hexclaveValue && stackValue && hexclaveValue !== stackValue) {\n throw new Error(`Environment variables ${hexclaveName} and ${stackName} are both set to different values. Remove one of them or set them to the same value.`);\n }\n return hexclaveValue || stackValue || undefined;\n}\n\n/**\n * Hexclave rebrand: resolve an env var by reading both the `HEXCLAVE_*` and\n * `STACK_*` spellings, preferring the canonical Hexclave value and falling back\n * to the legacy Stack value (empty counts as unset). Works in BOTH directions —\n * whether the caller passes the legacy `STACK_FOO` name or the canonical\n * `HEXCLAVE_FOO` name, the other spelling is still honored. Covers `STACK_FOO`,\n * `NEXT_PUBLIC_STACK_FOO`, `NEXT_PUBLIC_BROWSER_STACK_FOO`,\n * `NEXT_PUBLIC_SERVER_STACK_FOO`, `VITE_STACK_FOO` and their HEXCLAVE_ twins.\n * Names with neither segment behave exactly as before.\n */\nfunction getEnvVarWithHexclaveFallback(name: string): string | undefined {\n if (name.includes(\"STACK_\")) {\n const hexclaveName = name.replace(\"STACK_\", \"HEXCLAVE_\");\n return resolveHexclaveStackEnvVarValue(hexclaveName, name, process.env[hexclaveName], process.env[name]);\n }\n if (name.includes(\"HEXCLAVE_\")) {\n const stackName = name.replace(\"HEXCLAVE_\", \"STACK_\");\n return resolveHexclaveStackEnvVarValue(name, stackName, process.env[name], process.env[stackName]);\n }\n return process.env[name];\n}\n\n/**\n * Returns the environment variable with the given name, returning the default (if given) or throwing an error (otherwise) if it's undefined or the empty string.\n */\nexport function getEnvVariable(name: string, defaultValue?: string | undefined): string {\n if (isBrowserLike()) {\n throw new Error(deindent`\n Can't use getEnvVariable on the client because Next.js transpiles expressions of the kind process.env.XYZ at build-time on the client.\n \n Use process.env.XYZ directly instead.\n `);\n }\n if (name === \"NEXT_RUNTIME\") {\n throw new Error(deindent`\n Can't use getEnvVariable to access the NEXT_RUNTIME environment variable because it's compiled into the client bundle.\n \n Use getNextRuntime() instead.\n `);\n }\n\n // throw error if the old name is used as the retrieve key\n for (const [newName, oldNames] of Object.entries(ENV_VAR_RENAME)) {\n if (oldNames?.includes(name)) {\n throwErr(`Environment variable ${name} has been renamed to ${newName}. Please update your configuration to use the new name.`);\n }\n }\n\n // Hexclave rebrand: prefer the HEXCLAVE_*-prefixed equivalent, fall back to the STACK_* name.\n // Treat the empty string as unset the checked-in .env templates define empty\n // HEXCLAVE_* placeholders, which must not shadow a real value under the legacy name.\n let value = getEnvVarWithHexclaveFallback(name);\n\n // check the key under the old name if the new name is not found\n const renamedNames = ENV_VAR_RENAME[name];\n if (!value && renamedNames != null) {\n for (const oldName of renamedNames) {\n value = getEnvVarWithHexclaveFallback(oldName);\n if (value) break;\n }\n }\n\n if (!value) {\n if (defaultValue !== undefined) {\n value = defaultValue;\n } else {\n throwErr(`Missing environment variable: ${name}`);\n }\n }\n\n return value;\n}\n\nexport function getEnvBoolean(name: string): boolean {\n const value = getEnvVariable(name, \"false\");\n if (value === \"true\") {\n return true;\n } else if (value === \"false\") {\n return false;\n } else {\n throw new HexclaveAssertionError(`Environment variable ${name} must be either \"true\" or \"false\": found ${JSON.stringify(value)}`);\n }\n}\n\nexport function getNextRuntime() {\n // This variable is compiled into the client bundle, so we can't use getEnvVariable here.\n return process.env.NEXT_RUNTIME || throwErr(\"Missing environment variable: NEXT_RUNTIME\");\n}\n\nexport function getNodeEnvironment() {\n return getEnvVariable(\"NODE_ENV\", \"\");\n}\n\n/**\n * Browser-safe access to `process.env` for server-only or genuinely dynamic\n * env-var lookups. Returns `undefined` when `process` is not defined (e.g. in\n * a Vite browser bundle without a `process` shim).\n *\n * Note: uses `process.env[name]` (bracket form), which is NOT recognized by\n * Next.js / webpack DefinePlugin for compile-time inlining. If you need\n * build-time inlining for a `NEXT_PUBLIC_*` var, use the literal dot-form at\n * the call site, guarded with `typeof process`:\n *\n * const value = (typeof process !== \"undefined\" ? process.env.NEXT_PUBLIC_FOO : undefined);\n */\nexport function getProcessEnv(name: string): string | undefined {\n if (typeof process === \"undefined\" || typeof process.env === \"undefined\") {\n return undefined;\n }\n // Hexclave rebrand: prefer the HEXCLAVE_*-prefixed equivalent, fall back to the STACK_* name.\n // Empty counts as unset the checked-in .env templates define empty HEXCLAVE_* placeholders,\n // which must not shadow a real value under the legacy name.\n return getEnvVarWithHexclaveFallback(name);\n}\n"],"mappings":";;;;AAGA,SAAgB,gBAAgB;AAC9B,QAAO,OAAO,WAAW,eAAe,OAAO,aAAa,eAAe,OAAO,SAAS,kBAAkB;;AAI/G,MAAM,iBAAuD,EAC3D,2BAA2B,CAAC,kBAAkB,wBAAwB,EACvE;AAED,SAAgB,gCAAgC,cAAsB,WAAmB,eAAmC,YAAoD;AAC9K,KAAI,iBAAiB,cAAc,kBAAkB,WACnD,OAAM,IAAI,MAAM,yBAAyB,aAAa,OAAO,UAAU,sFAAsF;AAE/J,QAAO,iBAAiB,cAAc;;;;;;;;;;;;AAaxC,SAAS,8BAA8B,MAAkC;AACvE,KAAI,KAAK,SAAS,SAAS,EAAE;EAC3B,MAAM,eAAe,KAAK,QAAQ,UAAU,YAAY;AACxD,SAAO,gCAAgC,cAAc,MAAM,QAAQ,IAAI,eAAe,QAAQ,IAAI,MAAM;;AAE1G,KAAI,K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ach, describe, expect, it, vi } from "vitest";
2
+ import { getEnvVariable, getProcessEnv, resolveHexclaveStackEnvVarValue } from "./env.js";
3
+
4
+ //#region src/utils/env.test.tsx
5
+ afterEach(() => {
6
+ vi.unstubAllEnvs();
7
+ });
8
+ describe("Hexclave/Stack env var dual-read", () => {
9
+ it("falls back to the legacy Stack name when the Hexclave value is empty", () => {
10
+ vi.stubEnv("NEXT_PUBLIC_HEXCLAVE_API_URL", "");
11
+ vi.stubEnv("NEXT_PUBLIC_STACK_API_URL", "https://stack.example.test");
12
+ expect(getEnvVariable("NEXT_PUBLIC_STACK_API_URL")).toBe("https://stack.example.test");
13
+ expect(getProcessEnv("NEXT_PUBLIC_STACK_API_URL")).toBe("https://stack.example.test");
14
+ });
15
+ it("allows both names when they have the same non-empty value", () => {
16
+ vi.stubEnv("NEXT_PUBLIC_HEXCLAVE_API_URL", "https://api.example.test");
17
+ vi.stubEnv("NEXT_PUBLIC_STACK_API_URL", "https://api.example.test");
18
+ expect(getEnvVariable("NEXT_PUBLIC_STACK_API_URL")).toBe("https://api.example.test");
19
+ expect(getProcessEnv("NEXT_PUBLIC_STACK_API_URL")).toBe("https://api.example.test");
20
+ });
21
+ it("throws when both names are non-empty and different", () => {
22
+ vi.stubEnv("NEXT_PUBLIC_HEXCLAVE_API_URL", "https://hexclave.example.test");
23
+ vi.stubEnv("NEXT_PUBLIC_STACK_API_URL", "https://stack.example.test");
24
+ expect(() => getEnvVariable("NEXT_PUBLIC_STACK_API_URL")).toThrow(/NEXT_PUBLIC_HEXCLAVE_API_URL.*NEXT_PUBLIC_STACK_API_URL.*different values/);
25
+ expect(() => getProcessEnv("NEXT_PUBLIC_STACK_API_URL")).toThrow(/NEXT_PUBLIC_HEXCLAVE_API_URL.*NEXT_PUBLIC_STACK_API_URL.*different values/);
26
+ });
27
+ it("checks renamed legacy aliases when falling back", () => {
28
+ vi.stubEnv("NEXT_PUBLIC_HEXCLAVE_URL", "https://hexclave-url.example.test");
29
+ vi.stubEnv("NEXT_PUBLIC_STACK_URL", "https://stack-url.example.test");
30
+ expect(() => getEnvVariable("NEXT_PUBLIC_STACK_API_URL")).toThrow(/NEXT_PUBLIC_HEXCLAVE_URL.*NEXT_PUBLIC_STACK_URL.*different values/);
31
+ });
32
+ it("returns undefined when both names are empty", () => {
33
+ expect(resolveHexclaveStackEnvVarValue("HEXCLAVE_FOO", "STACK_FOO", "", "")).toBeUndefined();
34
+ });
35
+ it("falls back to the legacy Stack name when a canonical Hexclave name is looked up", () => {
36
+ vi.stubEnv("NEXT_PUBLIC_STACK_API_URL", "https://stack.example.test");
37
+ expect(getEnvVariable("NEXT_PUBLIC_HEXCLAVE_API_URL")).toBe("https://stack.example.test");
38
+ expect(getProcessEnv("NEXT_PUBLIC_HEXCLAVE_API_URL")).toBe("https://stack.example.test");
39
+ });
40
+ it("throws on a conflict when a canonical Hexclave name is looked up", () => {
41
+ vi.stubEnv("NEXT_PUBLIC_HEXCLAVE_API_URL", "https://hexclave.example.test");
42
+ vi.stubEnv("NEXT_PUBLIC_STACK_API_URL", "https://stack.example.test");
43
+ expect(() => getEnvVariable("NEXT_PUBLIC_HEXCLAVE_API_URL")).toThrow(/NEXT_PUBLIC_HEXCLAVE_API_URL.*NEXT_PUBLIC_STACK_API_URL.*different values/);
44
+ });
45
+ });
46
+
47
+ //#endregion
48
+ export { };
49
+ //# sourceMappingURL=env.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env.test.js","names":[],"sources":["../../../src/utils/env.test.tsx"],"sourcesContent":["import { afterEach, describe, expect, it, vi } from \"vitest\";\nimport { getEnvVariable, getProcessEnv, resolveHexclaveStackEnvVarValue } from \"./env\";\n\nafterEach(() => {\n vi.unstubAllEnvs();\n});\n\ndescribe(\"Hexclave/Stack env var dual-read\", () => {\n it(\"falls back to the legacy Stack name when the Hexclave value is empty\", () => {\n vi.stubEnv(\"NEXT_PUBLIC_HEXCLAVE_API_URL\", \"\");\n vi.stubEnv(\"NEXT_PUBLIC_STACK_API_URL\", \"https://stack.example.test\");\n\n expect(getEnvVariable(\"NEXT_PUBLIC_STACK_API_URL\")).toBe(\"https://stack.example.test\");\n expect(getProcessEnv(\"NEXT_PUBLIC_STACK_API_URL\")).toBe(\"https://stack.example.test\");\n });\n\n it(\"allows both names when they have the same non-empty value\", () => {\n vi.stubEnv(\"NEXT_PUBLIC_HEXCLAVE_API_URL\", \"https://api.example.test\");\n vi.stubEnv(\"NEXT_PUBLIC_STACK_API_URL\", \"https://api.example.test\");\n\n expect(getEnvVariable(\"NEXT_PUBLIC_STACK_API_URL\")).toBe(\"https://api.example.test\");\n expect(getProcessEnv(\"NEXT_PUBLIC_STACK_API_URL\")).toBe(\"https://api.example.test\");\n });\n\n it(\"throws when both names are non-empty and different\", () => {\n vi.stubEnv(\"NEXT_PUBLIC_HEXCLAVE_API_URL\", \"https://hexclave.example.test\");\n vi.stubEnv(\"NEXT_PUBLIC_STACK_API_URL\", \"https://stack.example.test\");\n\n expect(() => getEnvVariable(\"NEXT_PUBLIC_STACK_API_URL\")).toThrow(/NEXT_PUBLIC_HEXCLAVE_API_URL.*NEXT_PUBLIC_STACK_API_URL.*different values/);\n expect(() => getProcessEnv(\"NEXT_PUBLIC_STACK_API_URL\")).toThrow(/NEXT_PUBLIC_HEXCLAVE_API_URL.*NEXT_PUBLIC_STACK_API_URL.*different values/);\n });\n\n it(\"checks renamed legacy aliases when falling back\", () => {\n vi.stubEnv(\"NEXT_PUBLIC_HEXCLAVE_URL\", \"https://hexclave-url.example.test\");\n vi.stubEnv(\"NEXT_PUBLIC_STACK_URL\", \"https://stack-url.example.test\");\n\n expect(() => getEnvVariable(\"NEXT_PUBLIC_STACK_API_URL\")).toThrow(/NEXT_PUBLIC_HEXCLAVE_URL.*NEXT_PUBLIC_STACK_URL.*different values/);\n });\n\n it(\"returns undefined when both names are empty\", () => {\n expect(resolveHexclaveStackEnvVarValue(\"HEXCLAVE_FOO\", \"STACK_FOO\", \"\", \"\")).toBeUndefined();\n });\n\n it(\"falls back to the legacy Stack name when a canonical Hexclave name is looked up\", () => {\n vi.stubEnv(\"NEXT_PUBLIC_STACK_API_URL\", \"https://stack.example.test\");\n\n // Caller passes the canonical HEXCLAVE_ name but only the legacy value is set.\n expect(getEnvVariable(\"NEXT_PUBLIC_HEXCLAVE_API_URL\")).toBe(\"https://stack.example.test\");\n expect(getProcessEnv(\"NEXT_PUBLIC_HEXCLAVE_API_URL\")).toBe(\"https://stack.example.test\");\n });\n\n it(\"throws on a conflict when a canonical Hexclave name is looked up\", () => {\n vi.stubEnv(\"NEXT_PUBLIC_HEXCLAVE_API_URL\", \"https://hexclave.example.test\");\n vi.stubEnv(\"NEXT_PUBLIC_STACK_API_URL\", \"https://stack.example.test\");\n\n expect(() => getEnvVariable(\"NEXT_PUBLIC_HEXCLAVE_API_URL\")).toThrow(/NEXT_PUBLIC_HEXCLAVE_API_URL.*NEXT_PUBLIC_STACK_API_URL.*different values/);\n });\n});\n"],"mappings":";;;;AAGA,gBAAgB;AACd,IAAG,eAAe;EAClB;AAEF,SAAS,0CAA0C;AACjD,IAAG,8EAA8E;AAC/E,KAAG,QAAQ,gCAAgC,GAAG;AAC9C,KAAG,QAAQ,6BAA6B,6BAA6B;AAErE,SAAO,eAAe,4BAA4B,CAAC,CAAC,KAAK,6BAA6B;AACtF,SAAO,cAAc,4BAA4B,CAAC,CAAC,KAAK,6BAA6B;GACrF;AAEF,IAAG,mEAAmE;AACpE,KAAG,QAAQ,gCAAgC,2BAA2B;AACtE,KAAG,QAAQ,6BAA6B,2BAA2B;AAEnE,SAAO,eAAe,4BAA4B,CAAC,CAAC,KAAK,2BAA2B;AACpF,SAAO,cAAc,4BAA4B,CAAC,CAAC,KAAK,2BAA2B;GACnF;AAEF,IAAG,4DAA4D;AAC7D,KAAG,QAAQ,gCAAgC,gCAAgC;AAC3E,KAAG,QAAQ,6BAA6B,6BAA6B;AAErE,eAAa,eAAe,4BAA4B,CAAC,CAAC,QAAQ,4EAA4E;AAC9I,eAAa,cAA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AA;;;;SACA,SAAA;;;;SACA,kBAAA;;;;SACA,mBAAA;;;;SACA,MAAA;;;;SACA,gBAAA;;;;SACA,QAAA;;;;SACA,eAAA;;;;SACA,oBAAA;;;;SACA,eAAA;;;;SACA,2BAAA;;;;SACA,0BAAA;;;;SAEA,mBAAA;;;;SACA,cAAA;;;;SACA,UAAA;;;;SACA,kBAAA;;;;SACA,cAAA;;;;SACA,uBAAA;;;;SACA,qBAAA;;;;SACA,mBAAA;;;;SACA,YAAA;;;;SACA,WAAA;;;;SACA,6BAAA;;;;iBAGC,IAAA,EAAM,gCAAA;EAAA,OAgBP,aAAA,CAAc,KAAA,YAAiB,KAAA,IAAS,WAAA;EAK/C,aAAA,CAAA;EAIA,aAAA,CAAA;EAIA,aAAA,CAAA;EAIA,OAAA,CAAA,GAAW,UAAA;EAIX,UAAA,CAAA,GAAc,MAAA;EAMd,iBAAA,CAAA,GAAqB,IAAA;;;;EAWrB,UAAA,CAAA,GAAc,IAAA;AAAA"}
@@ -54,7 +54,10 @@ var HexclaveAssertionError = class extends Error {
54
54
  },
55
55
  enumerable: false
56
56
  });
57
- if ((typeof process !== "undefined" ? process.env.NEXT_PUBLIC_STACK_DEBUGGER_ON_ASSERTION_ERROR : void 0) === "true") debugger;
57
+ const hexclaveDebuggerValue = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_HEXCLAVE_DEBUGGER_ON_ASSERTION_ERROR : void 0;
58
+ const stackDebuggerValue = typeof process !== "undefined" ? process.env.NEXT_PUBLIC_STACK_DEBUGGER_ON_ASSERTION_ERROR : void 0;
59
+ if (hexclaveDebuggerValue && stackDebuggerValue && hexclaveDebuggerValue !== stackDebuggerValue) throw new Error("Environment variables NEXT_PUBLIC_HEXCLAVE_DEBUGGER_ON_ASSERTION_ERROR and NEXT_PUBLIC_STACK_DEBUGGER_ON_ASSERTION_ERROR are both set to different values. Remove one of them or set them to the same value.");
60
+ if ((hexclaveDebuggerValue || stackDebuggerValue) === "true") debugger;
58
61
  }
59
62
  };
60
63
  HexclaveAssertionError.prototype.name = "HexclaveAssertionError";
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../../src/utils/errors.tsx"],"sourcesContent":["import { globalVar } from \"./globals\";\nimport { Json } from \"./json\";\nimport { pick } from \"./objects\";\nimport { nicify } from \"./strings\";\n\n\nexport function throwErr(errorMessage: string, extraData?: any): never;\nexport function throwErr(error: Error): never;\nexport function throwErr(...args: StatusErrorConstructorParameters): never;\nexport function throwErr(...args: any[]): never {\n if (typeof args[0] === \"string\") {\n throw new HexclaveAssertionError(args[0], args[1]);\n } else if (args[0] instanceof Error) {\n throw args[0];\n } else {\n // @ts-expect-error\n throw new StatusError(...args);\n }\n}\n\nfunction removeStacktraceNameLine(stack: string): string {\n // some browsers (eg. Chrome) prepend the stack with an extra line with the error name\n const addsNameLine = new Error().stack?.startsWith(\"Error\\n\");\n return stack.split(\"\\n\").slice(addsNameLine ? 1 : 0).join(\"\\n\");\n}\n\n\n/**\n * Concatenates the (original) stacktraces of the given errors onto the first.\n *\n * Note: Very often, the concatStacktracesIfRejected function in promises.tsx is an easier way to use this function.\n *\n * Useful when you invoke an async function to receive a promise without awaiting it immediately. Browsers are smart\n * enough to keep track of the call stack in async function calls when you invoke `.then` within the same async tick,\n * but if you don't, the stacktrace will be lost.\n *\n * Here's an example of the unwanted behavior:\n *\n * ```tsx\n * async function log() {\n * await wait(0); // put the task on the event loop\n * console.log(new Error().stack);\n * }\n *\n * async function main() {\n * await log(); // good; prints both \"log\" and \"main\" on the stacktrace\n * log(); // bad; prints only \"log\" on the stacktrace\n * }\n * ```\n */\nexport function concatStacktraces(first: Error, ...errors: Error[]): void {\n // some browsers (eg. Firefox) add an extra empty line at the end\n const addsEmptyLineAtEnd = first.stack?.endsWith(\"\\n\");\n\n\n // Add a reference to this function itself so that we know that stacktraces were concatenated\n // If you are coming here from a stacktrace, please know that the two parts before and after this line are different\n // stacktraces that were concatenated with concatStacktraces\n const separator = removeStacktraceNameLine(new Error().stack ?? \"\").split(\"\\n\")[0];\n\n\n for (const error of errors) {\n const toAppend = removeStacktraceNameLine(error.stack ?? \"\");\n first.stack += (addsEmptyLineAtEnd ? \"\" : \"\\n\") + separator + \"\\n\" + toAppend;\n }\n}\n\n\nexport class HexclaveAssertionError extends Error {\n constructor(message: string, public readonly extraData?: Record<string, any> & ErrorOptions) {\n const disclaimer = `\\n\\nThis is likely an error in Hexclave. Please make sure you are running the newest version and report it.`;\n super(`${message}${message.endsWith(disclaimer) ? \"\" : disclaimer}`, pick(extraData ?? {}, [\"cause\"]));\n\n Object.defineProperty(this, \"customCaptureExtraArgs\", {\n get() {\n return [this.extraData];\n },\n enumerable: false,\n });\n\n // Use literal dot-form (guarded with `typeof process`) so Next.js / webpack\n // DefinePlugin can inline the value at build time. See getProcessEnv in ./env.\n if ((typeof process !== \"undefined\" ? process.env.NEXT_PUBLIC_STACK_DEBUGGER_ON_ASSERTION_ERROR : undefined) === \"true\") {\n debugger;\n }\n }\n}\nHexclaveAssertionError.prototype.name = \"HexclaveAssertionError\";\n\n\nexport function errorToNiceString(error: unknown): string {\n if (!(error instanceof Error)) return `${typeof error}<${nicify(error)}>`;\n return nicify(error, { maxDepth: 8 });\n}\n\n\nexport type CaptureLevel = \"error\" | \"warning\";\n\ntype ErrorSink = (location: string, error: unknown, level: CaptureLevel, ...extraArgs: unknown[]) => void;\n\nconst errorSinks = new Set<ErrorSink>();\nexport function registerErrorSink(sink: ErrorSink): void {\n if (errorSinks.has(sink)) {\n return;\n }\n errorSinks.add(sink);\n}\nregisterErrorSink((location, error, level, ...extraArgs) => {\n const logger = level === \"warning\" ? console.warn : console.error;\n const colorCode = level === \"warning\" ? \"\\x1b[43m\" : \"\\x1b[41m\";\n const label = level === \"warning\" ? \"warning\" : \"error\";\n logger(\n `${colorCode}Captured ${label} in ${location}:`,\n // HACK: Log a nicified version of the error to get around buggy Next.js pretty-printing\n // https://www.reddit.com/r/nextjs/comments/1gkxdqe/comment/m19kxgn/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button\n errorToNiceString(error),\n ...extraArgs,\n \"\\x1b[0m\",\n );\n});\nregisterErrorSink((location, error, level, ...extraArgs) => {\n globalVar.hexclaveCapturedErrors = globalVar.hexclaveCapturedErrors ?? [];\n globalVar.hexclaveCapturedErrors.push({ location, error, level, extraArgs });\n});\n\nfunction dispatchToSinks(location: string, error: unknown, level: CaptureLevel): void {\n for (const sink of errorSinks) {\n sink(\n location,\n error,\n level,\n ...error && (typeof error === 'object' || typeof error === 'function') && \"customCaptureExtraArgs\" in error && Array.isArray(error.customCaptureExtraArgs) ? (error.customCaptureExtraArgs as any[]) : [],\n );\n }\n}\n\n/**\n * Captures an error and sends it to the error sinks (most notably, Sentry). Errors caught with captureError are\n * supposed to be seen by an engineer, so they should be actionable and important.\n *\n * The location string is a machine-readable ID, and should hence not contain spaces or anything like that. Good\n * examples are: \"api-route-handler\", \"renderPart()\", etc.\n *\n * Errors that bubble up to the top of runAsynchronously or a route handler are already captured with captureError.\n */\nexport function captureError(location: string, error: unknown): void {\n dispatchToSinks(location, error, \"error\");\n}\n\n/**\n * Like captureError, but logs at warning level. Use for issues that an engineer should know about but that aren't\n * severe enough to be treated as an error (e.g. recoverable failures in background tasks).\n */\nexport function captureWarning(location: string, error: unknown): void {\n dispatchToSinks(location, error, \"warning\");\n}\n\n\ntype Status = {\n statusCode: number,\n message: string,\n};\n\ntype StatusErrorConstructorParameters =\n| [\n status: Status,\n message?: string\n]\n| [\n statusCode: number | Status,\n message: string,\n];\n\nexport class StatusError extends Error {\n private readonly __stackStatusErrorBrand = \"stack-status-error-brand-sentinel\" as const;\n public name = \"StatusError\";\n public readonly statusCode: number;\n\n public static BadRequest = { statusCode: 400, message: \"Bad Request\" };\n public static Unauthorized = { statusCode: 401, message: \"Unauthorized\" };\n public static PaymentRequired = { statusCode: 402, message: \"Payment Required\" };\n public static Forbidden = { statusCode: 403, message: \"Forbidden\" };\n public static NotFound = { statusCode: 404, message: \"Not Found\" };\n public static MethodNotAllowed = { statusCode: 405, message: \"Method Not Allowed\" };\n public static NotAcceptable = { statusCode: 406, message: \"Not Acceptable\" };\n public static ProxyAuthenticationRequired = { statusCode: 407, message: \"Proxy Authentication Required\" };\n public static RequestTimeout = { statusCode: 408, message: \"Request Timeout\" };\n public static Conflict = { statusCode: 409, message: \"Conflict\" };\n public static Gone = { statusCode: 410, message: \"Gone\" };\n public static LengthRequired = { statusCode: 411, message: \"Length Required\" };\n public static PreconditionFailed = { statusCode: 412, message: \"Precondition Failed\" };\n public static PayloadTooLarge = { statusCode: 413, message: \"Payload Too Large\" };\n public static URITooLong = { statusCode: 414, message: \"URI Too Long\" };\n public static UnsupportedMediaType = { statusCode: 415, message: \"Unsupported Media Type\" };\n public static RangeNotSatisfiable = { statusCode: 416, message: \"Range Not Satisfiable\" };\n public static ExpectationFailed = { statusCode: 417, message: \"Expectation Failed\" };\n public static ImATeapot = { statusCode: 418, message: \"I'm a teapot\" };\n public static MisdirectedRequest = { statusCode: 421, message: \"Misdirected Request\" };\n public static UnprocessableEntity = { statusCode: 422, message: \"Unprocessable Entity\" };\n public static Locked = { statusCode: 423, message: \"Locked\" };\n public static FailedDependency = { statusCode: 424, message: \"Failed Dependency\" };\n public static TooEarly = { statusCode: 425, message: \"Too Early\" };\n public static UpgradeRequired = { statusCode: 426, message: \"Upgrade Required\" };\n public static PreconditionRequired = { statusCode: 428, message: \"Precondition Required\" };\n public static TooManyRequests = { statusCode: 429, message: \"Too Many Requests\" };\n public static RequestHeaderFieldsTooLarge = { statusCode: 431, message: \"Request Header Fields Too Large\" };\n public static UnavailableForLegalReasons = { statusCode: 451, message: \"Unavailable For Legal Reasons\" };\n\n public static InternalServerError = { statusCode: 500, message: \"Internal Server Error\" };\n public static NotImplemented = { statusCode: 501, message: \"Not Implemented\" };\n public static BadGateway = { statusCode: 502, message: \"Bad Gateway\" };\n public static ServiceUnavailable = { statusCode: 503, message: \"Service Unavailable\" };\n public static GatewayTimeout = { statusCode: 504, message: \"Gateway Timeout\" };\n public static HTTPVersionNotSupported = { statusCode: 505, message: \"HTTP Version Not Supported\" };\n public static VariantAlsoNegotiates = { statusCode: 506, message: \"Variant Also Negotiates\" };\n public static InsufficientStorage = { statusCode: 507, message: \"Insufficient Storage\" };\n public static LoopDetected = { statusCode: 508, message: \"Loop Detected\" };\n public static NotExtended = { statusCode: 510, message: \"Not Extended\" };\n public static NetworkAuthenticationRequired = { statusCode: 511, message: \"Network Authentication Required\" };\n\n\n constructor(...args: StatusErrorConstructorParameters);\n constructor(\n status: number | Status,\n message?: string,\n ) {\n if (typeof status === \"object\") {\n message ??= status.message;\n status = status.statusCode;\n }\n super(message);\n this.statusCode = status;\n if (!message) {\n throw new HexclaveAssertionError(\"StatusError always requires a message unless a Status object is passed\", { cause: this });\n }\n }\n\n public static isStatusError(error: unknown): error is StatusError {\n // like instanceof, but also works for errors thrown in other realms or by different versions of the same package\n return typeof error === \"object\" && error !== null && \"__stackStatusErrorBrand\" in error && error.__stackStatusErrorBrand === \"stack-status-error-brand-sentinel\";\n }\n\n public isClientError() {\n return this.statusCode >= 400 && this.statusCode < 500;\n }\n\n public isServerError() {\n return !this.isClientError();\n }\n\n public getStatusCode(): number {\n return this.statusCode;\n }\n\n public getBody(): Uint8Array {\n return new TextEncoder().encode(this.message);\n }\n\n public getHeaders(): Record<string, string[]> {\n return {\n \"Content-Type\": [\"text/plain; charset=utf-8\"],\n };\n }\n\n public toDescriptiveJson(): Json {\n return {\n status_code: this.getStatusCode(),\n message: this.message,\n headers: this.getHeaders(),\n };\n }\n\n /**\n * @deprecated this is not a good way to make status errors human-readable, use toDescriptiveJson instead\n */\n public toHttpJson(): Json {\n return {\n status_code: this.statusCode,\n body: this.message,\n headers: this.getHeaders(),\n };\n }\n}\nStatusError.prototype.name = \"StatusError\";\n"],"mappings":";;;;;AASA,SAAgB,SAAS,GAAG,MAAoB;AAC9C,KAAI,OAAO,KAAK,OAAO,SACrB,OAAM,IAAI,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AAK,SAAS;GAAmC;;CAI7G,YACE,QACA,SACA;AACA,MAAI,OAAO,WAAW,UAAU;AAC9B,eAAY,OAAO;AACnB,YAAS,OAAO;;AAElB,QAAM,QAAQ;iCAxD2B;cAC7B;AAwDZ,OAAK,aAAa;AAClB,MAAI,CAAC,QACH,OAAM,IAAI,uBAAuB,0EAA0E,EAAE,OAAO,MAAM,CAAC;;CAI/H,OAAc,cAAc,OAAsC;AAEhE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,6BAA6B,SAAS,MAAM,4BAA4B;;CAGhI,AAAO,gBAAgB;AACrB,SAAO,KAAK,cAAc,OAAO,KAAK,aAAa;;CAGrD,AAAO,gBAAgB;AACrB,SAAO,CAAC,KAAK,eAAe;;CAG9B,AAAO,gBAAwB;AAC7B,SAAO,KAAK;;CAGd,AAAO,UAAsB;AAC3B,SAAO,IAAI,aAAa,CAAC,OAAO,KAAK,QAAQ;;CAG/C,AAAO,aAAuC;AAC5C,SAAO,EACL,gBAAgB,CAAC,4BAA4B,EAC9C;;CAGH,AAAO,oBAA0B;AAC/B,SAAO;GACL,aAAa,KAAK,eAAe;GACjC,SAAS,KAAK;GACd,SAAS,KAAK,YAAY;GAC3B;;;;;CAMH,AAAO,aAAmB;AACxB,SAAO;GACL,aAAa,KAAK;GAClB,MAAM,KAAK;GACX,SAAS,KAAK,YAAY;GAC3B;;;AAGL,YAAY,UAAU,OAAO"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../../src/utils/errors.tsx"],"sourcesContent":["import { globalVar } from \"./globals\";\nimport { Json } from \"./json\";\nimport { pick } from \"./objects\";\nimport { nicify } from \"./strings\";\n\n\nexport function throwErr(errorMessage: string, extraData?: any): never;\nexport function throwErr(error: Error): never;\nexport function throwErr(...args: StatusErrorConstructorParameters): never;\nexport function throwErr(...args: any[]): never {\n if (typeof args[0] === \"string\") {\n throw new HexclaveAssertionError(args[0], args[1]);\n } else if (args[0] instanceof Error) {\n throw args[0];\n } else {\n // @ts-expect-error\n throw new StatusError(...args);\n }\n}\n\nfunction removeStacktraceNameLine(stack: string): string {\n // some browsers (eg. Chrome) prepend the stack with an extra line with the error name\n const addsNameLine = new Error().stack?.startsWith(\"Error\\n\");\n return stack.split(\"\\n\").slice(addsNameLine ? 1 : 0).join(\"\\n\");\n}\n\n\n/**\n * Concatenates the (original) stacktraces of the given errors onto the first.\n *\n * Note: Very often, the concatStacktracesIfRejected function in promises.tsx is an easier way to use this function.\n *\n * Useful when you invoke an async function to receive a promise without awaiting it immediately. Browsers are smart\n * enough to keep track of the call stack in async function calls when you invoke `.then` within the same async tick,\n * but if you don't, the stacktrace will be lost.\n *\n * Here's an example of the unwanted behavior:\n *\n * ```tsx\n * async function log() {\n * await wait(0); // put the task on the event loop\n * console.log(new Error().stack);\n * }\n *\n * async function main() {\n * await log(); // good; prints both \"log\" and \"main\" on the stacktrace\n * log(); // bad; prints only \"log\" on the stacktrace\n * }\n * ```\n */\nexport function concatStacktraces(first: Error, ...errors: Error[]): void {\n // some browsers (eg. Firefox) add an extra empty line at the end\n const addsEmptyLineAtEnd = first.stack?.endsWith(\"\\n\");\n\n\n // Add a reference to this function itself so that we know that stacktraces were concatenated\n // If you are coming here from a stacktrace, please know that the two parts before and after this line are different\n // stacktraces that were concatenated with concatStacktraces\n const separator = removeStacktraceNameLine(new Error().stack ?? \"\").split(\"\\n\")[0];\n\n\n for (const error of errors) {\n const toAppend = removeStacktraceNameLine(error.stack ?? \"\");\n first.stack += (addsEmptyLineAtEnd ? \"\" : \"\\n\") + separator + \"\\n\" + toAppend;\n }\n}\n\n\nexport class HexclaveAssertionError extends Error {\n constructor(message: string, public readonly extraData?: Record<string, any> & ErrorOptions) {\n const disclaimer = `\\n\\nThis is likely an error in Hexclave. Please make sure you are running the newest version and report it.`;\n super(`${message}${message.endsWith(disclaimer) ? \"\" : disclaimer}`, pick(extraData ?? {}, [\"cause\"]));\n\n Object.defineProperty(this, \"customCaptureExtraArgs\", {\n get() {\n return [this.extraData];\n },\n enumerable: false,\n });\n\n // Use literal dot-form (guarded with `typeof process`) so Next.js / webpack\n // DefinePlugin can inline the value at build time. See getProcessEnv in ./env.\n const hexclaveDebuggerValue = typeof process !== \"undefined\" ? process.env.NEXT_PUBLIC_HEXCLAVE_DEBUGGER_ON_ASSERTION_ERROR : undefined;\n const stackDebuggerValue = typeof process !== \"undefined\" ? process.env.NEXT_PUBLIC_STACK_DEBUGGER_ON_ASSERTION_ERROR : undefined;\n if (hexclaveDebuggerValue && stackDebuggerValue && hexclaveDebuggerValue !== stackDebuggerValue) {\n throw new Error(\"Environment variables NEXT_PUBLIC_HEXCLAVE_DEBUGGER_ON_ASSERTION_ERROR and NEXT_PUBLIC_STACK_DEBUGGER_ON_ASSERTION_ERROR are both set to different values. Remove one of them or set them to the same value.\");\n }\n if ((hexclaveDebuggerValue || stackDebuggerValue) === \"true\") {\n debugger;\n }\n }\n}\nHexclaveAssertionError.prototype.name = \"HexclaveAssertionError\";\n\n\nexport function errorToNiceString(error: unknown): string {\n if (!(error instanceof Error)) return `${typeof error}<${nicify(error)}>`;\n return nicify(error, { maxDepth: 8 });\n}\n\n\nexport type CaptureLevel = \"error\" | \"warning\";\n\ntype ErrorSink = (location: string, error: unknown, level: CaptureLevel, ...extraArgs: unknown[]) => void;\n\nconst errorSinks = new Set<ErrorSink>();\nexport function registerErrorSink(sink: ErrorSink): void {\n if (errorSinks.has(sink)) {\n return;\n }\n errorSinks.add(sink);\n}\nregisterErrorSink((location, error, level, ...extraArgs) => {\n const logger = level === \"warning\" ? console.warn : console.error;\n const colorCode = level === \"warning\" ? \"\\x1b[43m\" : \"\\x1b[41m\";\n const label = level === \"warning\" ? \"warning\" : \"error\";\n logger(\n `${colorCode}Captured ${label} in ${location}:`,\n // HACK: Log a nicified version of the error to get around buggy Next.js pretty-printing\n // https://www.reddit.com/r/nextjs/comments/1gkxdqe/comment/m19kxgn/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button\n errorToNiceString(error),\n ...extraArgs,\n \"\\x1b[0m\",\n );\n});\nregisterErrorSink((location, error, level, ...extraArgs) => {\n globalVar.hexclaveCapturedErrors = globalVar.hexclaveCapturedErrors ?? [];\n globalVar.hexclaveCapturedErrors.push({ location, error, level, extraArgs });\n});\n\nfunction dispatchToSinks(location: string, error: unknown, level: CaptureLevel): void {\n for (const sink of errorSinks) {\n sink(\n location,\n error,\n level,\n ...error && (typeof error === 'object' || typeof error === 'function') && \"customCaptureExtraArgs\" in error && Array.isArray(error.customCaptureExtraArgs) ? (error.customCaptureExtraArgs as any[]) : [],\n );\n }\n}\n\n/**\n * Captures an error and sends it to the error sinks (most notably, Sentry). Errors caught with captureError are\n * supposed to be seen by an engineer, so they should be actionable and important.\n *\n * The location string is a machine-readable ID, and should hence not contain spaces or anything like that. Good\n * examples are: \"api-route-handler\", \"renderPart()\", etc.\n *\n * Errors that bubble up to the top of runAsynchronously or a route handler are already captured with captureError.\n */\nexport function captureError(location: string, error: unknown): void {\n dispatchToSinks(location, error, \"error\");\n}\n\n/**\n * Like captureError, but logs at warning level. Use for issues that an engineer should know about but that aren't\n * severe enough to be treated as an error (e.g. recoverable failures in background tasks).\n */\nexport function captureWarning(location: string, error: unknown): void {\n dispatchToSinks(location, error, \"warning\");\n}\n\n\ntype Status = {\n statusCode: number,\n message: string,\n};\n\ntype StatusErrorConstructorParameters =\n| [\n status: Status,\n message?: string\n]\n| [\n statusCode: number | Status,\n message: string,\n];\n\nexport class StatusError extends Error {\n private readonly __stackStatusErrorBrand = \"stack-status-error-brand-sentinel\" as const;\n public name = \"StatusError\";\n public readonly statusCode: number;\n\n public static BadRequest = { statusCode: 400, message: \"Bad Request\" };\n public static Unauthorized = { statusCode: 401, message: \"Unauthorized\" };\n public static PaymentRequired = { statusCode: 402, message: \"Payment Required\" };\n public static Forbidden = { statusCode: 403, message: \"Forbidden\" };\n public static NotFound = { statusCode: 404, message: \"Not Found\" };\n public static MethodNotAllowed = { statusCode: 405, message: \"Method Not Allowed\" };\n public static NotAcceptable = { statusCode: 406, message: \"Not Acceptable\" };\n public static ProxyAuthenticationRequired = { statusCode: 407, message: \"Proxy Authentication Required\" };\n public static RequestTimeout = { statusCode: 408, message: \"Request Timeout\" };\n public static Conflict = { statusCode: 409, message: \"Conflict\" };\n public static Gone = { statusCode: 410, message: \"Gone\" };\n public static LengthRequired = { statusCode: 411, message: \"Length Required\" };\n public static PreconditionFailed = { statusCode: 412, message: \"Precondition Failed\" };\n public static PayloadTooLarge = { statusCode: 413, message: \"Payload Too Large\" };\n public static URITooLong = { statusCode: 414, message: \"URI Too Long\" };\n public static UnsupportedMediaType = { statusCode: 415, message: \"Unsupported Media Type\" };\n public static RangeNotSatisfiable = { statusCode: 416, message: \"Range Not Satisfiable\" };\n public static ExpectationFailed = { statusCode: 417, message: \"Expectation Failed\" };\n public static ImATeapot = { statusCode: 418, message: \"I'm a teapot\" };\n public static MisdirectedRequest = { statusCode: 421, message: \"Misdirected Request\" };\n public static UnprocessableEntity = { statusCode: 422, message: \"Unprocessable Entity\" };\n public static Locked = { statusCode: 423, message: \"Locked\" };\n public static FailedDependency = { statusCode: 424, message: \"Failed Dependency\" };\n public static TooEarly = { statusCode: 425, message: \"Too Early\" };\n public static UpgradeRequired = { statusCode: 426, message: \"Upgrade Required\" };\n public static PreconditionRequired = { statusCode: 428, message: \"Precondition Required\" };\n public static TooManyRequests = { statusCode: 429, message: \"Too Many Requests\" };\n public static RequestHeaderFieldsTooLarge = { statusCode: 431, message: \"Request Header Fields Too Large\" };\n public static UnavailableForLegalReasons = { statusCode: 451, message: \"Unavailable For Legal Reasons\" };\n\n public static InternalServerError = { statusCode: 500, message: \"Internal Server Error\" };\n public static NotImplemented = { statusCode: 501, message: \"Not Implemented\" };\n public static BadGateway = { statusCode: 502, message: \"Bad Gateway\" };\n public static ServiceUnavailable = { statusCode: 503, message: \"Service Unavailable\" };\n public static GatewayTimeout = { statusCode: 504, message: \"Gateway Timeout\" };\n public static HTTPVersionNotSupported = { statusCode: 505, message: \"HTTP Version Not Supported\" };\n public static VariantAlsoNegotiates = { statusCode: 506, message: \"Variant Also Negotiates\" };\n public static InsufficientStorage = { statusCode: 507, message: \"Insufficient Storage\" };\n public static LoopDetected = { statusCode: 508, message: \"Loop Detected\" };\n public static NotExtended = { statusCode: 510, message: \"Not Extended\" };\n public static NetworkAuthenticationRequired = { statusCode: 511, message: \"Network Authentication Required\" };\n\n\n constructor(...args: StatusErrorConstructorParameters);\n constructor(\n status: number | Status,\n message?: string,\n ) {\n if (typeof status === \"object\") {\n message ??= status.message;\n status = status.statusCode;\n }\n super(message);\n this.statusCode = status;\n if (!message) {\n throw new HexclaveAssertionError(\"StatusError always requires a message unless a Status object is passed\", { cause: this });\n }\n }\n\n public static isStatusError(error: unknown): error is StatusError {\n // like instanceof, but also works for errors thrown in other realms or by different versions of the same package\n return typeof error === \"object\" && error !== null && \"__stackStatusErrorBrand\" in error && error.__stackStatusErrorBrand === \"stack-status-error-brand-sentinel\";\n }\n\n public isClientError() {\n return this.statusCode >= 400 && this.statusCode < 500;\n }\n\n public isServerError() {\n return !this.isClientError();\n }\n\n public getStatusCode(): number {\n return this.statusCode;\n }\n\n public getBody(): Uint8Array {\n return new TextEncoder().encode(this.message);\n }\n\n public getHeaders(): Record<string, string[]> {\n return {\n \"Content-Type\": [\"text/plain; charset=utf-8\"],\n };\n }\n\n public toDescriptiveJson(): Json {\n return {\n status_code: this.getStatusCode(),\n message: this.message,\n headers: this.getHeaders(),\n };\n }\n\n /**\n * @deprecated this is not a good way to make status errors human-readable, use toDescriptiveJson instead\n */\n public toHttpJson(): Json {\n return {\n status_code: this.statusCode,\n body: this.message,\n headers: this.getHeaders(),\n };\n }\n}\nStatusError.prototype.name = \"StatusError\";\n"],"mappings":";;;;;AASA,SAAgB,SAAS,GAAG,MAAoB;AAC9C,KAAI,OAAO,KAAK,OAAO,SACrB,OAAM,IAAI,uBAAuB,KAAK,IAAI,KAAK,GAAG;UACzC,KAAK,cAAc,MAC5B,OAA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