()
| 83 | }; |
| 84 | |
| 85 | async function main() { |
| 86 | const state = process.argv[2]; |
| 87 | const orgId = process.argv[3] ?? 'openpanel-dev'; |
| 88 | |
| 89 | if (!state || !recipes[state]) { |
| 90 | console.error( |
| 91 | `Usage: set-subscription-state <state> [orgId]\n\nStates: ${Object.keys(recipes).join(', ')}` |
| 92 | ); |
| 93 | process.exitCode = 1; |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | const recipe = recipes[state](); |
| 98 | await db.organization.update({ where: { id: orgId }, data: recipe }); |
| 99 | |
| 100 | // Compute the resolved state ignoring SELF_HOSTED so the printout reflects |
| 101 | // what the dashboard shows when billing is enabled. |
| 102 | delete process.env.SELF_HOSTED; |
| 103 | const resolved = getSubscriptionState(recipe); |
| 104 | |
| 105 | console.log(`Set ${orgId} -> requested "${state}", resolves to "${resolved}"`); |
| 106 | console.table({ |
| 107 | subscriptionStatus: recipe.subscriptionStatus, |
| 108 | subscriptionCanceledAt: recipe.subscriptionCanceledAt?.toISOString() ?? null, |
| 109 | subscriptionStartsAt: recipe.subscriptionStartsAt?.toISOString() ?? null, |
| 110 | subscriptionEndsAt: recipe.subscriptionEndsAt?.toISOString() ?? null, |
| 111 | }); |
| 112 | if (resolved !== state) { |
| 113 | console.warn( |
| 114 | `Heads up: resolves to "${resolved}", not "${state}" (status + dates combination).` |
| 115 | ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | main() |
| 120 | .catch((error) => { |
no test coverage detected