prpm 0.1.4 → 0.1.6

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.
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ /**
3
+ * Subscribe command - Subscribe to PRPM+ for monthly credits
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleSubscribe = handleSubscribe;
7
+ exports.createSubscribeCommand = createSubscribeCommand;
8
+ const commander_1 = require("commander");
9
+ const user_config_1 = require("../core/user-config");
10
+ const telemetry_1 = require("../core/telemetry");
11
+ const child_process_1 = require("child_process");
12
+ const util_1 = require("util");
13
+ const execAsync = (0, util_1.promisify)(child_process_1.exec);
14
+ /**
15
+ * Make authenticated API call
16
+ */
17
+ async function apiCall(endpoint) {
18
+ const config = await (0, user_config_1.getConfig)();
19
+ const baseUrl = (config.registryUrl || "https://registry.prpm.dev").replace(/\/$/, '');
20
+ if (!config.token) {
21
+ throw new Error('Authentication required. Please run `prpm login` first.');
22
+ }
23
+ const response = await fetch(`${baseUrl}${endpoint}`, {
24
+ headers: {
25
+ Authorization: `Bearer ${config.token}`,
26
+ },
27
+ });
28
+ if (!response.ok) {
29
+ const errorData = await response.json().catch(() => ({}));
30
+ throw new Error(errorData.message || `API request failed: ${response.statusText}`);
31
+ }
32
+ return response;
33
+ }
34
+ /**
35
+ * Get current subscription status
36
+ */
37
+ async function getSubscriptionStatus() {
38
+ const response = await apiCall('/api/v1/playground/credits');
39
+ return response.json();
40
+ }
41
+ /**
42
+ * Open URL in default browser
43
+ */
44
+ async function openBrowser(url) {
45
+ const platform = process.platform;
46
+ let command;
47
+ if (platform === 'darwin') {
48
+ command = `open "${url}"`;
49
+ }
50
+ else if (platform === 'win32') {
51
+ command = `start "" "${url}"`;
52
+ }
53
+ else {
54
+ // Linux and other Unix-like systems
55
+ command = `xdg-open "${url}"`;
56
+ }
57
+ try {
58
+ await execAsync(command);
59
+ }
60
+ catch (error) {
61
+ // If automatic opening fails, just show the URL
62
+ console.log(`\nšŸ”— Please open this URL in your browser:`);
63
+ console.log(` ${url}`);
64
+ }
65
+ }
66
+ /**
67
+ * Poll for subscription status change
68
+ */
69
+ async function pollForSubscription(initialStatus, maxAttempts = 60, intervalMs = 2000) {
70
+ console.log('\nā³ Waiting for subscription confirmation...');
71
+ console.log(' (This may take a minute. Press Ctrl+C to cancel)');
72
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
73
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
74
+ try {
75
+ const status = await getSubscriptionStatus();
76
+ if (status.prpm_plus_status === 'active' && initialStatus !== 'active') {
77
+ return true;
78
+ }
79
+ // Show progress indicator
80
+ if (attempt % 5 === 0 && attempt > 0) {
81
+ process.stdout.write('.');
82
+ }
83
+ }
84
+ catch (error) {
85
+ // Continue polling even if there's an error
86
+ continue;
87
+ }
88
+ }
89
+ return false;
90
+ }
91
+ /**
92
+ * Handle the subscribe command
93
+ */
94
+ async function handleSubscribe() {
95
+ const startTime = Date.now();
96
+ let success = false;
97
+ let error;
98
+ try {
99
+ const config = await (0, user_config_1.getConfig)();
100
+ if (!config.token) {
101
+ console.error('āŒ Authentication required');
102
+ console.log('\nšŸ’” Please login first:');
103
+ console.log(' prpm login');
104
+ process.exit(1);
105
+ }
106
+ // Get current status
107
+ console.log('šŸ” Checking current subscription status...');
108
+ const initialStatus = await getSubscriptionStatus();
109
+ if (initialStatus.prpm_plus_status === 'active') {
110
+ console.log('\nāœ… You are already subscribed to PRPM+!');
111
+ console.log(`\nšŸ“Š Current benefits:`);
112
+ console.log(` šŸ’° Monthly credits: ${initialStatus.monthly_credits}`);
113
+ console.log(` šŸ“¦ Priority support`);
114
+ console.log(` šŸš€ Early access to new features`);
115
+ console.log('\nšŸ’” Manage your subscription at:');
116
+ console.log(' https://prpm.dev/settings/billing');
117
+ process.exit(0);
118
+ }
119
+ console.log('\n✨ Subscribe to PRPM+ and get:');
120
+ console.log(' šŸ’° 100 monthly playground credits');
121
+ console.log(' ā™»ļø Rollover unused credits (up to 200)');
122
+ console.log(' šŸ“¦ Priority support');
123
+ console.log(' šŸš€ Early access to new features');
124
+ console.log('\nšŸ’µ Pricing:');
125
+ console.log(' $6/month for individuals');
126
+ console.log(' $3/month for verified organization members (50% off)');
127
+ // Open subscription page
128
+ const subscribeUrl = `${(config.registryUrl || "https://registry.prpm.dev").replace(/api\/?$/, '')}/playground/credits/subscribe`;
129
+ console.log(`\n🌐 Opening subscription page in your browser...`);
130
+ await openBrowser(subscribeUrl);
131
+ // Poll for subscription confirmation
132
+ const subscribed = await pollForSubscription(initialStatus.prpm_plus_status);
133
+ if (subscribed) {
134
+ const updatedStatus = await getSubscriptionStatus();
135
+ console.log('\n\nšŸŽ‰ Successfully subscribed to PRPM+!');
136
+ console.log('\nšŸ“Š Your benefits:');
137
+ console.log(` šŸ’° Monthly credits: ${updatedStatus.monthly_credits}`);
138
+ console.log(` šŸ’³ Current balance: ${updatedStatus.balance} credits`);
139
+ console.log('\nāœ… You can now:');
140
+ console.log(' - Test packages in playground: prpm playground <package> "<input>"');
141
+ console.log(' - Check credits anytime: prpm credits');
142
+ success = true;
143
+ }
144
+ else {
145
+ console.log('\n\nā±ļø Subscription process timed out or was canceled.');
146
+ console.log('\nšŸ’” If you completed the subscription, run this to verify:');
147
+ console.log(' prpm credits');
148
+ console.log('\nšŸ’” Or visit your account settings:');
149
+ console.log(' https://prpm.dev/settings/billing');
150
+ }
151
+ }
152
+ catch (err) {
153
+ error = err instanceof Error ? err.message : String(err);
154
+ console.error(`\nāŒ Subscription failed: ${error}`);
155
+ process.exit(1);
156
+ }
157
+ finally {
158
+ await telemetry_1.telemetry.track({
159
+ command: 'subscribe',
160
+ success,
161
+ error,
162
+ duration: Date.now() - startTime,
163
+ });
164
+ await telemetry_1.telemetry.shutdown();
165
+ }
166
+ }
167
+ /**
168
+ * Create the subscribe command
169
+ */
170
+ function createSubscribeCommand() {
171
+ const command = new commander_1.Command('subscribe');
172
+ command
173
+ .description('Subscribe to PRPM+ for monthly playground credits and benefits')
174
+ .addHelpText('after', `
175
+ PRPM+ Benefits:
176
+ ✨ 100 monthly playground credits (worth $6+ in API costs)
177
+ ā™»ļø Rollover unused credits up to 200 (1-month expiry)
178
+ šŸ“¦ Priority support and bug fixes
179
+ šŸš€ Early access to new features
180
+ šŸ’¬ Access to PRPM+ community
181
+
182
+ Pricing:
183
+ Individual: $6/month
184
+ Organization: $3/month (50% discount for verified org members)
185
+
186
+ How it works:
187
+ 1. Opens subscription page in your browser
188
+ 2. Complete payment with Stripe
189
+ 3. Credits are added automatically
190
+ 4. Start testing packages immediately
191
+
192
+ Examples:
193
+ # Subscribe to PRPM+
194
+ $ prpm subscribe
195
+
196
+ # After subscribing, check your credits
197
+ $ prpm credits
198
+
199
+ # Test packages in playground
200
+ $ prpm playground @anthropic/assistant "Help me brainstorm ideas"
201
+
202
+ Note: You can cancel anytime from https://prpm.dev/settings/billing
203
+ `)
204
+ .action(async () => {
205
+ await handleSubscribe();
206
+ process.exit(0);
207
+ });
208
+ return command;
209
+ }
package/dist/index.js CHANGED
@@ -27,6 +27,10 @@ const schema_1 = require("./commands/schema");
27
27
  const init_1 = require("./commands/init");
28
28
  const config_1 = require("./commands/config");
29
29
  const catalog_1 = require("./commands/catalog");
30
+ const playground_1 = require("./commands/playground");
31
+ const credits_1 = require("./commands/credits");
32
+ const subscribe_1 = require("./commands/subscribe");
33
+ const buy_credits_1 = require("./commands/buy-credits");
30
34
  const telemetry_2 = require("./core/telemetry");
31
35
  // Read version from package.json
32
36
  function getVersion() {
@@ -65,6 +69,11 @@ program.addCommand((0, list_1.createListCommand)());
65
69
  program.addCommand((0, uninstall_1.createUninstallCommand)());
66
70
  program.addCommand((0, index_1.createIndexCommand)());
67
71
  program.addCommand((0, telemetry_1.createTelemetryCommand)());
72
+ // Playground commands
73
+ program.addCommand((0, playground_1.createPlaygroundCommand)());
74
+ program.addCommand((0, credits_1.createCreditsCommand)());
75
+ program.addCommand((0, subscribe_1.createSubscribeCommand)());
76
+ program.addCommand((0, buy_credits_1.createBuyCreditsCommand)());
68
77
  // Utility commands
69
78
  program.addCommand((0, schema_1.createSchemaCommand)());
70
79
  program.addCommand((0, config_1.createConfigCommand)());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prpm",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Prompt Package Manager CLI - Install and manage prompt-based files",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -45,8 +45,8 @@
45
45
  "license": "MIT",
46
46
  "dependencies": {
47
47
  "@octokit/rest": "^22.0.0",
48
- "@pr-pm/registry-client": "^1.3.3",
49
- "@pr-pm/types": "^0.2.3",
48
+ "@pr-pm/registry-client": "^1.3.4",
49
+ "@pr-pm/types": "^0.2.6",
50
50
  "ajv": "^8.17.1",
51
51
  "ajv-formats": "^3.0.1",
52
52
  "commander": "^11.1.0",