@chuzi/shared 1.3.38 → 1.3.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,6 +9,25 @@ function computeSceneVisibility(sceneList, opts) {
9
9
  }));
10
10
  }
11
11
 
12
+ // src/config/credits.ts
13
+ var CREDIT_CENTS_PER_UNIT = {
14
+ watch: 5,
15
+ create: 10
16
+ };
17
+ var CREDITS_PER_DOLLAR = {
18
+ watch: 20,
19
+ create: 10
20
+ };
21
+ function defaultPurchaseCredits(pool) {
22
+ return CREDITS_PER_DOLLAR[pool];
23
+ }
24
+ function priceCentsForCredits(pool, credits) {
25
+ return Math.max(1, credits) * CREDIT_CENTS_PER_UNIT[pool];
26
+ }
27
+ function formatCreditPrice(cents) {
28
+ return `$${(cents / 100).toFixed(2)}`;
29
+ }
30
+
12
31
  // src/config/index.ts
13
32
  var REALM_IDS = ["cosmos", "wilds"];
14
33
  var SUPPORTED_LOCALES = [
@@ -187,6 +206,22 @@ var REALMS = {
187
206
  editor_ai_retry: "Retransmit",
188
207
  editor_ai_feedback_prompt: "How should we adjust the signal?",
189
208
  editor_ai_credit_cost: "1 Stardust per signal",
209
+ spending_modal_title: "Refuel Your Mission",
210
+ spending_modal_body: "You need more credits to continue. Choose how many to add.",
211
+ spending_modal_no_payment: "Add a payment method to purchase credits.",
212
+ spending_modal_credits_label: "Credits to add",
213
+ spending_modal_price_label: "Total",
214
+ spending_modal_admin_note: "Admin \u2014 credits are granted free of charge.",
215
+ spending_modal_purchase: "Purchase Credits",
216
+ spending_modal_grant: "Grant Credits",
217
+ spending_modal_add_card: "Add Payment Method",
218
+ spending_modal_card_last_four: "Card last four digits",
219
+ spending_modal_card_label: "Card label (optional)",
220
+ spending_modal_processing: "Processing\u2026",
221
+ spending_modal_success: "Credits added.",
222
+ spending_modal_error: "Could not complete purchase. Try again.",
223
+ spending_modal_cancel: "Not now",
224
+ spending_insufficient_credits: "Not enough credits. Purchase more to continue.",
190
225
  editor_ai_generating_scene: "Planet forming\u2026",
191
226
  editor_ai_style_badge: "Signal Style",
192
227
  editor_ai_failed: "Signal lost. Try retransmitting.",
@@ -261,8 +296,13 @@ var REALMS = {
261
296
  tags_label: "Signal Tags",
262
297
  tags_placeholder: "Search signal tags\u2026",
263
298
  tags_empty: "No signal tags yet",
299
+ tags_required: "At least one signal tag is required.",
264
300
  story_picker_label: "Constellations",
265
301
  created_by: "Directed by",
302
+ chosen_by: "Chosen by",
303
+ story_metadata_heading: "Star system details",
304
+ story_metadata_save: "Save",
305
+ constellation_title_edit_hint: "Edit star system title and details",
266
306
  director_profile_title: "Director profile",
267
307
  director_profile_name_label: "Name",
268
308
  director_profile_realm_label: "Experience realm",
@@ -495,6 +535,22 @@ var REALMS = {
495
535
  editor_ai_retry: "Regrow",
496
536
  editor_ai_feedback_prompt: "How should we reshape the growth?",
497
537
  editor_ai_credit_cost: "1 Pollen per bloom",
538
+ spending_modal_title: "Gather More Pollen",
539
+ spending_modal_body: "You need more credits to continue. Choose how many to add.",
540
+ spending_modal_no_payment: "Add a payment method to purchase credits.",
541
+ spending_modal_credits_label: "Credits to add",
542
+ spending_modal_price_label: "Total",
543
+ spending_modal_admin_note: "Admin \u2014 credits are granted free of charge.",
544
+ spending_modal_purchase: "Purchase Credits",
545
+ spending_modal_grant: "Grant Credits",
546
+ spending_modal_add_card: "Add Payment Method",
547
+ spending_modal_card_last_four: "Card last four digits",
548
+ spending_modal_card_label: "Card label (optional)",
549
+ spending_modal_processing: "Processing\u2026",
550
+ spending_modal_success: "Credits added.",
551
+ spending_modal_error: "Could not complete purchase. Try again.",
552
+ spending_modal_cancel: "Not now",
553
+ spending_insufficient_credits: "Not enough credits. Purchase more to continue.",
498
554
  editor_ai_generating_scene: "Clearing emerging\u2026",
499
555
  editor_ai_style_badge: "Growth Style",
500
556
  editor_ai_failed: "Growth withered. Try regrowing.",
@@ -569,8 +625,13 @@ var REALMS = {
569
625
  tags_label: "Root Tags",
570
626
  tags_placeholder: "Search root tags\u2026",
571
627
  tags_empty: "No root tags yet",
628
+ tags_required: "At least one root tag is required.",
572
629
  story_picker_label: "Groves",
573
630
  created_by: "Tended by",
631
+ chosen_by: "Chosen by",
632
+ story_metadata_heading: "Grove details",
633
+ story_metadata_save: "Save",
634
+ constellation_title_edit_hint: "Edit grove title and details",
574
635
  director_profile_title: "Director profile",
575
636
  director_profile_name_label: "Name",
576
637
  director_profile_realm_label: "Experience realm",
@@ -801,6 +862,22 @@ var FALLBACK_LEXICON = {
801
862
  editor_ai_retry: "Try Again",
802
863
  editor_ai_feedback_prompt: "What should we change?",
803
864
  editor_ai_credit_cost: "1 credit per generation",
865
+ spending_modal_title: "Purchase Credits",
866
+ spending_modal_body: "You need more credits to continue. Choose how many to add.",
867
+ spending_modal_no_payment: "Add a payment method to purchase credits.",
868
+ spending_modal_credits_label: "Credits to add",
869
+ spending_modal_price_label: "Total",
870
+ spending_modal_admin_note: "Admin \u2014 credits are granted free of charge.",
871
+ spending_modal_purchase: "Purchase Credits",
872
+ spending_modal_grant: "Grant Credits",
873
+ spending_modal_add_card: "Add Payment Method",
874
+ spending_modal_card_last_four: "Card last four digits",
875
+ spending_modal_card_label: "Card label (optional)",
876
+ spending_modal_processing: "Processing\u2026",
877
+ spending_modal_success: "Credits added.",
878
+ spending_modal_error: "Could not complete purchase. Try again.",
879
+ spending_modal_cancel: "Not now",
880
+ spending_insufficient_credits: "Not enough credits. Purchase more to continue.",
804
881
  editor_ai_generating_scene: "Scene generating\u2026",
805
882
  editor_ai_style_badge: "Style",
806
883
  editor_ai_failed: "Generation failed. Please try again.",
@@ -875,8 +952,13 @@ var FALLBACK_LEXICON = {
875
952
  tags_label: "Tags",
876
953
  tags_placeholder: "Search tags\u2026",
877
954
  tags_empty: "No tags yet",
955
+ tags_required: "At least one tag is required.",
878
956
  story_picker_label: "Stories",
879
957
  created_by: "Created by",
958
+ chosen_by: "Chosen by",
959
+ story_metadata_heading: "Story details",
960
+ story_metadata_save: "Save",
961
+ constellation_title_edit_hint: "Edit story title and details",
880
962
  director_profile_title: "Director profile",
881
963
  director_profile_name_label: "Name",
882
964
  director_profile_realm_label: "Experience realm",
@@ -1139,6 +1221,23 @@ var ChuziApiError = class extends Error {
1139
1221
  status;
1140
1222
  body;
1141
1223
  };
1224
+ function isInsufficientCreditsError(err) {
1225
+ if (!(err instanceof ChuziApiError) || err.status !== 403) {
1226
+ return false;
1227
+ }
1228
+ const body = err.body;
1229
+ return typeof body?.error === "string" && /insufficient/i.test(body.error);
1230
+ }
1231
+ function insufficientCreditsPool(err) {
1232
+ if (!isInsufficientCreditsError(err)) {
1233
+ return null;
1234
+ }
1235
+ const body = err.body;
1236
+ const message = body.error ?? "";
1237
+ if (/watch/i.test(message)) return "watch";
1238
+ if (/create/i.test(message)) return "create";
1239
+ return null;
1240
+ }
1142
1241
  function buildQuery(query) {
1143
1242
  if (!query) return "";
1144
1243
  const params = new URLSearchParams();
@@ -1273,9 +1372,30 @@ function createChuziClient(config) {
1273
1372
  balance: (opts) => request("GET", "/api/v1/credits/balance", opts),
1274
1373
  ledger: (opts) => request("GET", "/api/v1/credits/ledger", {
1275
1374
  signal: opts?.signal,
1276
- query: { cursor: opts?.cursor, limit: opts?.limit }
1375
+ query: opts?.pool ? { pool: opts.pool } : void 0
1376
+ }),
1377
+ packs: (opts) => request("GET", "/api/v1/credits/packs", opts),
1378
+ uploadCost: (fileSize, opts) => request("GET", "/api/v1/credits/upload-cost", {
1379
+ signal: opts?.signal,
1380
+ query: { file_size: fileSize }
1277
1381
  }),
1278
- packs: (opts) => request("GET", "/api/v1/credits/packs", opts)
1382
+ purchase: (req) => request("POST", "/api/v1/credits/purchase", { body: req }),
1383
+ purchaseAmount: (req) => request("POST", "/api/v1/credits/purchase-amount", { body: req }),
1384
+ unlockScene: (sceneId, opts) => request("POST", `/api/v1/scenes/${encodeURIComponent(sceneId)}/unlock`, opts)
1385
+ },
1386
+ payments: {
1387
+ list: (opts) => request("GET", "/api/v1/payments/methods", opts),
1388
+ store: (req) => request("POST", "/api/v1/payments/methods", { body: req }),
1389
+ remove: (paymentMethodId) => request("DELETE", `/api/v1/payments/methods/${encodeURIComponent(paymentMethodId)}`),
1390
+ setDefault: (paymentMethodId) => request(
1391
+ "POST",
1392
+ `/api/v1/payments/methods/${encodeURIComponent(paymentMethodId)}/default`
1393
+ )
1394
+ },
1395
+ admin: {
1396
+ credits: {
1397
+ grant: (req) => request("POST", "/api/v1/admin/credits/grant", { body: req })
1398
+ }
1279
1399
  },
1280
1400
  ai: {
1281
1401
  generateImage: (req) => request("POST", "/api/v1/ai/generate-image", { body: req }),
@@ -1397,6 +1517,6 @@ function isLikelyVideoUrl(url, mediaType) {
1397
1517
  return /\.(mp4|webm|mov|m3u8)(\?|$)/i.test(url);
1398
1518
  }
1399
1519
 
1400
- export { CONTENT_RATINGS, CONTENT_RATING_IDS, ChuziApiError, DEFAULT_LOCALE, FALLBACK_LEXICON, FALLBACK_LOCALES, Intent, LOCALE_LABELS, REALMS, REALM_IDS, SCENE_TREE_THEMES, SUPPORTED_LOCALES, THEME_TOKENS, computeScenePreviewMs, computeSceneVisibility, createChuziClient, defaultFocusSnap, getRealmLexiconOverrides, getSceneTreeTheme, getThemeTokens, isContentRating, isLikelyImageUrl, isLikelyVideoUrl, isSupportedLocale, lexiconForRealm, matchAcceptLanguage, mergeIntentSources, normalizeLocale, previewMsWhenVisible, resolveChoiceTiming, setRealmLexiconOverrides, t };
1520
+ export { CONTENT_RATINGS, CONTENT_RATING_IDS, CREDITS_PER_DOLLAR, CREDIT_CENTS_PER_UNIT, ChuziApiError, DEFAULT_LOCALE, FALLBACK_LEXICON, FALLBACK_LOCALES, Intent, LOCALE_LABELS, REALMS, REALM_IDS, SCENE_TREE_THEMES, SUPPORTED_LOCALES, THEME_TOKENS, computeScenePreviewMs, computeSceneVisibility, createChuziClient, defaultFocusSnap, defaultPurchaseCredits, formatCreditPrice, getRealmLexiconOverrides, getSceneTreeTheme, getThemeTokens, insufficientCreditsPool, isContentRating, isInsufficientCreditsError, isLikelyImageUrl, isLikelyVideoUrl, isSupportedLocale, lexiconForRealm, matchAcceptLanguage, mergeIntentSources, normalizeLocale, previewMsWhenVisible, priceCentsForCredits, resolveChoiceTiming, setRealmLexiconOverrides, t };
1401
1521
  //# sourceMappingURL=index.js.map
1402
1522
  //# sourceMappingURL=index.js.map