undohaven-core 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "undohaven-core",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "description": "Snapshot, encryption, and restore engine for UndoHaven.",
6
6
  "engines": {
@@ -28,11 +28,11 @@
28
28
  "homepage": "https://undohaven.com/",
29
29
  "repository": {
30
30
  "type": "git",
31
- "url": "git+https://github.com/Antipas/undohaven.git",
31
+ "url": "git+https://github.com/OWNER/undohaven.git",
32
32
  "directory": "packages/core"
33
33
  },
34
34
  "bugs": {
35
- "url": "https://github.com/Antipas/undohaven/issues",
35
+ "url": "https://github.com/OWNER/undohaven/issues",
36
36
  "email": "support@undohaven.com"
37
37
  }
38
38
  }
package/src/engine.js CHANGED
@@ -216,8 +216,8 @@ export async function createSnapshot(opts) {
216
216
  }
217
217
  const storage = await loadStorageConfig(dataDir)
218
218
  const byo = storage.mode === 's3' || storage.mode === 'dir'
219
- if (byo) {
220
- await opts.cloud.createSnapshot({
219
+ const created = byo
220
+ ? await opts.cloud.createSnapshot({
221
221
  id,
222
222
  createdAt,
223
223
  kind,
@@ -229,23 +229,25 @@ export async function createSnapshot(opts) {
229
229
  encryptedManifest: record.encryptedManifest,
230
230
  pinned: record.pinned,
231
231
  })
232
- } else {
233
- const missing = await opts.cloud.missing(record.chunkIds)
234
- for (const chunkId of missing) {
235
- await opts.cloud.uploadChunk(chunkId, await readPaddedChunk(dataDir, chunkId))
236
- }
237
- await opts.cloud.createSnapshot({
238
- id,
239
- createdAt,
240
- kind,
241
- bytes,
242
- chunkIds: record.chunkIds,
243
- dshVersion: versions.dshVersion,
244
- includesCredentials: includeCredentials,
245
- encryptedManifest: record.encryptedManifest,
246
- pinned: record.pinned,
247
- })
248
- }
232
+ : await (async () => {
233
+ const missing = await opts.cloud.missing(record.chunkIds)
234
+ for (const chunkId of missing) {
235
+ await opts.cloud.uploadChunk(chunkId, await readPaddedChunk(dataDir, chunkId))
236
+ }
237
+ return opts.cloud.createSnapshot({
238
+ id,
239
+ createdAt,
240
+ kind,
241
+ bytes,
242
+ chunkIds: record.chunkIds,
243
+ dshVersion: versions.dshVersion,
244
+ includesCredentials: includeCredentials,
245
+ encryptedManifest: record.encryptedManifest,
246
+ pinned: record.pinned,
247
+ })
248
+ })()
249
+ record.pruned = Number(created?.pruned || 0)
250
+ record.plan = created?.plan || null
249
251
  record.cloud = true
250
252
  await writeSnapshotRecord(dataDir, record)
251
253
  } catch (error) {
package/src/funnel.js CHANGED
@@ -1,10 +1,13 @@
1
1
  import { loadConfig } from './keys.js'
2
2
  import { readPrompts, writePrompts } from './prompts.js'
3
3
 
4
- export const ANONYMOUS_FUNNEL = new Set(['install', 'first_snapshot', 'rollback', 'limit_hit'])
4
+ export const ANONYMOUS_FUNNEL = new Set(['install', 'first_snapshot', 'rollback', 'limit_hit', 'copy_install'])
5
5
 
6
6
  const SCOPES = new Set(['sessions', 'storages', 'config', 'all'])
7
- const LIMITS = new Set(['quota', 'device', 'snapshot'])
7
+ const LIMITS = new Set(['quota', 'device', 'snapshot', 'history'])
8
+ const UTM_SOURCES = new Set(['github', 'x', 'awesome', 'direct'])
9
+
10
+ export const TRIAL_URL = 'https://undohaven.com/pricing?utm_source=cli&utm_medium=limit'
8
11
 
9
12
  export function funnelOptedIn(config, env = {}) {
10
13
  const flag = env.UNDOHAVEN_FUNNEL
@@ -22,9 +25,33 @@ export function anonymousMeta(name, meta) {
22
25
  const reason = LIMITS.has(meta?.reason) ? meta.reason : 'quota'
23
26
  return { reason }
24
27
  }
28
+ if (name === 'copy_install') {
29
+ const source = UTM_SOURCES.has(meta?.source) ? meta.source : 'direct'
30
+ return { source }
31
+ }
25
32
  return null
26
33
  }
27
34
 
35
+ export function limitNudgeLine(kind) {
36
+ if (kind === 'history') {
37
+ return `Free history is 7 days. A 14-day Pro trial needs no card: ${TRIAL_URL}`
38
+ }
39
+ return `A second device needs Pro. A 14-day trial needs no card: ${TRIAL_URL}`
40
+ }
41
+
42
+ /** Print-once local flag. The funnel ping stays inside reportAnonymousEvent, so it is sent only when opted in. */
43
+ export async function showLimitNudge(dataDir, kind, env = process.env) {
44
+ const prompts = await readPrompts(dataDir)
45
+ const nudges = prompts.nudges && typeof prompts.nudges === 'object' ? { ...prompts.nudges } : {}
46
+ if (nudges[kind]) return { shown: false, line: '' }
47
+ nudges[kind] = true
48
+ prompts.nudges = nudges
49
+ await writePrompts(dataDir, prompts)
50
+ const reason = kind === 'history' ? 'history' : 'device'
51
+ await reportAnonymousEvent(dataDir, 'limit_hit', { reason }, env).catch(() => {})
52
+ return { shown: true, line: limitNudgeLine(kind) }
53
+ }
54
+
28
55
  /** Opt-in, account-free funnel ping. No token is sent. */
29
56
  export async function reportAnonymousEvent(dataDir, name, meta, env = process.env) {
30
57
  if (!ANONYMOUS_FUNNEL.has(name)) return { sent: false, reason: 'name' }
package/src/index.js CHANGED
@@ -61,5 +61,5 @@ export {
61
61
  export { PLANS, PRICES, PRICE_ENV, effectivePlan, versionLine, isCrossMajorDowngrade } from './plans.js'
62
62
  export { padBlob, unpadBlob, loadStorageConfig, saveStorageConfig, redactStorage, s3Call, newDeviceLabel } from './byo.js'
63
63
  export { UPGRADE, readPrompts, writePrompts } from './prompts.js'
64
- export { ANONYMOUS_FUNNEL, anonymousMeta, funnelOptedIn, reportAnonymousEvent } from './funnel.js'
64
+ export { ANONYMOUS_FUNNEL, anonymousMeta, funnelOptedIn, limitNudgeLine, reportAnonymousEvent, showLimitNudge, TRIAL_URL } from './funnel.js'
65
65
  export { readPaddedChunk } from './store.js'
@@ -3,7 +3,7 @@ import { mkdtemp, rm } from 'node:fs/promises'
3
3
  import { tmpdir } from 'node:os'
4
4
  import { join } from 'node:path'
5
5
  import test from 'node:test'
6
- import { anonymousMeta, funnelOptedIn, reportAnonymousEvent } from '../src/funnel.js'
6
+ import { anonymousMeta, funnelOptedIn, reportAnonymousEvent, showLimitNudge } from '../src/funnel.js'
7
7
  import { loadConfig, saveConfig } from '../src/keys.js'
8
8
 
9
9
  test('anonymous funnel is opt-in and strips paths', async () => {
@@ -20,3 +20,16 @@ test('anonymous funnel is opt-in and strips paths', async () => {
20
20
  assert.equal(offline.sent, false)
21
21
  await rm(dir, { recursive: true, force: true })
22
22
  })
23
+
24
+ test('a free-limit trial line is printed once per limit type', async () => {
25
+ const dir = await mkdtemp(join(tmpdir(), 'nudge-'))
26
+ const first = await showLimitNudge(dir, 'history', {})
27
+ const again = await showLimitNudge(dir, 'history', {})
28
+ const device = await showLimitNudge(dir, 'device', {})
29
+ assert.equal(first.shown, true)
30
+ assert.match(first.line, /14-day Pro trial/)
31
+ assert.match(first.line, /utm_source=cli&utm_medium=limit/)
32
+ assert.equal(again.shown, false)
33
+ assert.equal(device.shown, true)
34
+ await rm(dir, { recursive: true, force: true })
35
+ })