@chuzi/shared 1.3.37 → 1.3.39

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 = [
@@ -156,6 +175,8 @@ var REALMS = {
156
175
  editor_choices: "Choices",
157
176
  editor_scene_settings: "Star Settings",
158
177
  editor_title_scene: "Title Star",
178
+ editor_film_title: "Star System Title",
179
+ editor_film_title_hint: "Click to rename this star system",
159
180
  editor_ending_scene: "Final Star",
160
181
  editor_play: "Engage",
161
182
  editor_pause: "Hold",
@@ -185,6 +206,22 @@ var REALMS = {
185
206
  editor_ai_retry: "Retransmit",
186
207
  editor_ai_feedback_prompt: "How should we adjust the signal?",
187
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.",
188
225
  editor_ai_generating_scene: "Planet forming\u2026",
189
226
  editor_ai_style_badge: "Signal Style",
190
227
  editor_ai_failed: "Signal lost. Try retransmitting.",
@@ -462,6 +499,8 @@ var REALMS = {
462
499
  editor_choices: "Choices",
463
500
  editor_scene_settings: "Clearing Settings",
464
501
  editor_title_scene: "Title Clearing",
502
+ editor_film_title: "Grove Title",
503
+ editor_film_title_hint: "Click to rename this grove",
465
504
  editor_ending_scene: "Roots",
466
505
  editor_play: "Unfurl",
467
506
  editor_pause: "Rest",
@@ -491,6 +530,22 @@ var REALMS = {
491
530
  editor_ai_retry: "Regrow",
492
531
  editor_ai_feedback_prompt: "How should we reshape the growth?",
493
532
  editor_ai_credit_cost: "1 Pollen per bloom",
533
+ spending_modal_title: "Gather More Pollen",
534
+ spending_modal_body: "You need more credits to continue. Choose how many to add.",
535
+ spending_modal_no_payment: "Add a payment method to purchase credits.",
536
+ spending_modal_credits_label: "Credits to add",
537
+ spending_modal_price_label: "Total",
538
+ spending_modal_admin_note: "Admin \u2014 credits are granted free of charge.",
539
+ spending_modal_purchase: "Purchase Credits",
540
+ spending_modal_grant: "Grant Credits",
541
+ spending_modal_add_card: "Add Payment Method",
542
+ spending_modal_card_last_four: "Card last four digits",
543
+ spending_modal_card_label: "Card label (optional)",
544
+ spending_modal_processing: "Processing\u2026",
545
+ spending_modal_success: "Credits added.",
546
+ spending_modal_error: "Could not complete purchase. Try again.",
547
+ spending_modal_cancel: "Not now",
548
+ spending_insufficient_credits: "Not enough credits. Purchase more to continue.",
494
549
  editor_ai_generating_scene: "Clearing emerging\u2026",
495
550
  editor_ai_style_badge: "Growth Style",
496
551
  editor_ai_failed: "Growth withered. Try regrowing.",
@@ -766,6 +821,8 @@ var FALLBACK_LEXICON = {
766
821
  editor_choices: "Choices",
767
822
  editor_scene_settings: "Scene Settings",
768
823
  editor_title_scene: "Title Scene",
824
+ editor_film_title: "Film Title",
825
+ editor_film_title_hint: "Click to rename this film",
769
826
  editor_ending_scene: "Ending Scene",
770
827
  editor_play: "Play",
771
828
  editor_pause: "Pause",
@@ -795,6 +852,22 @@ var FALLBACK_LEXICON = {
795
852
  editor_ai_retry: "Try Again",
796
853
  editor_ai_feedback_prompt: "What should we change?",
797
854
  editor_ai_credit_cost: "1 credit per generation",
855
+ spending_modal_title: "Purchase Credits",
856
+ spending_modal_body: "You need more credits to continue. Choose how many to add.",
857
+ spending_modal_no_payment: "Add a payment method to purchase credits.",
858
+ spending_modal_credits_label: "Credits to add",
859
+ spending_modal_price_label: "Total",
860
+ spending_modal_admin_note: "Admin \u2014 credits are granted free of charge.",
861
+ spending_modal_purchase: "Purchase Credits",
862
+ spending_modal_grant: "Grant Credits",
863
+ spending_modal_add_card: "Add Payment Method",
864
+ spending_modal_card_last_four: "Card last four digits",
865
+ spending_modal_card_label: "Card label (optional)",
866
+ spending_modal_processing: "Processing\u2026",
867
+ spending_modal_success: "Credits added.",
868
+ spending_modal_error: "Could not complete purchase. Try again.",
869
+ spending_modal_cancel: "Not now",
870
+ spending_insufficient_credits: "Not enough credits. Purchase more to continue.",
798
871
  editor_ai_generating_scene: "Scene generating\u2026",
799
872
  editor_ai_style_badge: "Style",
800
873
  editor_ai_failed: "Generation failed. Please try again.",
@@ -1133,6 +1206,23 @@ var ChuziApiError = class extends Error {
1133
1206
  status;
1134
1207
  body;
1135
1208
  };
1209
+ function isInsufficientCreditsError(err) {
1210
+ if (!(err instanceof ChuziApiError) || err.status !== 403) {
1211
+ return false;
1212
+ }
1213
+ const body = err.body;
1214
+ return typeof body?.error === "string" && /insufficient/i.test(body.error);
1215
+ }
1216
+ function insufficientCreditsPool(err) {
1217
+ if (!isInsufficientCreditsError(err)) {
1218
+ return null;
1219
+ }
1220
+ const body = err.body;
1221
+ const message = body.error ?? "";
1222
+ if (/watch/i.test(message)) return "watch";
1223
+ if (/create/i.test(message)) return "create";
1224
+ return null;
1225
+ }
1136
1226
  function buildQuery(query) {
1137
1227
  if (!query) return "";
1138
1228
  const params = new URLSearchParams();
@@ -1267,9 +1357,30 @@ function createChuziClient(config) {
1267
1357
  balance: (opts) => request("GET", "/api/v1/credits/balance", opts),
1268
1358
  ledger: (opts) => request("GET", "/api/v1/credits/ledger", {
1269
1359
  signal: opts?.signal,
1270
- query: { cursor: opts?.cursor, limit: opts?.limit }
1360
+ query: opts?.pool ? { pool: opts.pool } : void 0
1361
+ }),
1362
+ packs: (opts) => request("GET", "/api/v1/credits/packs", opts),
1363
+ uploadCost: (fileSize, opts) => request("GET", "/api/v1/credits/upload-cost", {
1364
+ signal: opts?.signal,
1365
+ query: { file_size: fileSize }
1271
1366
  }),
1272
- packs: (opts) => request("GET", "/api/v1/credits/packs", opts)
1367
+ purchase: (req) => request("POST", "/api/v1/credits/purchase", { body: req }),
1368
+ purchaseAmount: (req) => request("POST", "/api/v1/credits/purchase-amount", { body: req }),
1369
+ unlockScene: (sceneId, opts) => request("POST", `/api/v1/scenes/${encodeURIComponent(sceneId)}/unlock`, opts)
1370
+ },
1371
+ payments: {
1372
+ list: (opts) => request("GET", "/api/v1/payments/methods", opts),
1373
+ store: (req) => request("POST", "/api/v1/payments/methods", { body: req }),
1374
+ remove: (paymentMethodId) => request("DELETE", `/api/v1/payments/methods/${encodeURIComponent(paymentMethodId)}`),
1375
+ setDefault: (paymentMethodId) => request(
1376
+ "POST",
1377
+ `/api/v1/payments/methods/${encodeURIComponent(paymentMethodId)}/default`
1378
+ )
1379
+ },
1380
+ admin: {
1381
+ credits: {
1382
+ grant: (req) => request("POST", "/api/v1/admin/credits/grant", { body: req })
1383
+ }
1273
1384
  },
1274
1385
  ai: {
1275
1386
  generateImage: (req) => request("POST", "/api/v1/ai/generate-image", { body: req }),
@@ -1391,6 +1502,6 @@ function isLikelyVideoUrl(url, mediaType) {
1391
1502
  return /\.(mp4|webm|mov|m3u8)(\?|$)/i.test(url);
1392
1503
  }
1393
1504
 
1394
- 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 };
1505
+ 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 };
1395
1506
  //# sourceMappingURL=index.js.map
1396
1507
  //# sourceMappingURL=index.js.map