MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / main

Function main

packages/db/scripts/set-subscription-state.ts:85–117  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83};
84
85async 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
119main()
120 .catch((error) => {

Callers 1

Calls 5

getSubscriptionStateFunction · 0.90
joinMethod · 0.80
errorMethod · 0.45
logMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected