@timeback/sdk 0.1.7 → 0.1.8

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.
Files changed (109) hide show
  1. package/README.md +91 -2
  2. package/dist/chunk-07j8zre9.js +2 -0
  3. package/dist/chunk-3886xy48.js +8 -0
  4. package/dist/chunk-9se82640.js +1 -0
  5. package/dist/chunk-ahy54f2r.js +2 -0
  6. package/dist/chunk-ewsp6v3b.js +16 -0
  7. package/dist/chunk-j1xdrfqj.js +2 -0
  8. package/dist/chunk-qaa129bd.js +2 -0
  9. package/dist/chunk-qr0bbnsr.js +1 -0
  10. package/dist/chunk-rgbpvxbv.js +1 -0
  11. package/dist/chunk-whc53e0y.js +11 -0
  12. package/dist/client/adapters/react/hooks/types.d.ts +46 -0
  13. package/dist/client/adapters/react/hooks/types.d.ts.map +1 -1
  14. package/dist/client/adapters/react/hooks/useTimebackProfile.d.ts +42 -0
  15. package/dist/client/adapters/react/hooks/useTimebackProfile.d.ts.map +1 -0
  16. package/dist/client/adapters/react/index.d.ts +2 -1
  17. package/dist/client/adapters/react/index.d.ts.map +1 -1
  18. package/dist/client/adapters/react/index.js +2 -494
  19. package/dist/client/adapters/solid/index.d.ts +3 -0
  20. package/dist/client/adapters/solid/index.d.ts.map +1 -1
  21. package/dist/client/adapters/solid/index.ts +12 -0
  22. package/dist/client/adapters/solid/primitives/createTimebackProfile.d.ts +58 -0
  23. package/dist/client/adapters/solid/primitives/createTimebackProfile.d.ts.map +1 -0
  24. package/dist/client/adapters/solid/primitives/createTimebackProfile.ts +209 -0
  25. package/dist/client/adapters/solid/primitives/createTimebackVerification.d.ts +36 -0
  26. package/dist/client/adapters/solid/primitives/createTimebackVerification.d.ts.map +1 -0
  27. package/dist/client/adapters/solid/primitives/createTimebackVerification.ts +133 -0
  28. package/dist/client/adapters/solid/types.d.ts +86 -0
  29. package/dist/client/adapters/solid/types.d.ts.map +1 -0
  30. package/dist/client/adapters/solid/types.ts +85 -0
  31. package/dist/client/adapters/svelte/index.d.ts +2 -1
  32. package/dist/client/adapters/svelte/index.d.ts.map +1 -1
  33. package/dist/client/adapters/svelte/index.ts +11 -2
  34. package/dist/client/adapters/svelte/{stores.d.ts → stores/client.d.ts} +11 -9
  35. package/dist/client/adapters/svelte/stores/client.d.ts.map +1 -0
  36. package/dist/client/adapters/svelte/{stores.ts → stores/client.ts} +24 -52
  37. package/dist/client/adapters/svelte/stores/index.d.ts +10 -0
  38. package/dist/client/adapters/svelte/stores/index.d.ts.map +1 -0
  39. package/dist/client/adapters/svelte/stores/index.ts +22 -0
  40. package/dist/client/adapters/svelte/stores/profile.d.ts +66 -0
  41. package/dist/client/adapters/svelte/stores/profile.d.ts.map +1 -0
  42. package/dist/client/adapters/svelte/stores/profile.ts +168 -0
  43. package/dist/client/adapters/svelte/stores/verification.d.ts +43 -0
  44. package/dist/client/adapters/svelte/stores/verification.d.ts.map +1 -0
  45. package/dist/client/adapters/svelte/stores/verification.ts +126 -0
  46. package/dist/client/adapters/svelte/types.d.ts +35 -0
  47. package/dist/client/adapters/svelte/types.d.ts.map +1 -0
  48. package/dist/client/adapters/vue/composables/useTimebackProfile.d.ts +51 -0
  49. package/dist/client/adapters/vue/composables/useTimebackProfile.d.ts.map +1 -0
  50. package/dist/client/adapters/vue/composables/useTimebackProfile.ts +186 -0
  51. package/dist/client/adapters/vue/composables/useTimebackVerification.d.ts +44 -0
  52. package/dist/client/adapters/vue/composables/useTimebackVerification.d.ts.map +1 -0
  53. package/dist/client/adapters/vue/composables/useTimebackVerification.ts +128 -0
  54. package/dist/client/adapters/vue/index.d.ts +3 -0
  55. package/dist/client/adapters/vue/index.d.ts.map +1 -1
  56. package/dist/client/adapters/vue/index.ts +12 -1
  57. package/dist/client/adapters/vue/types.d.ts +86 -0
  58. package/dist/client/adapters/vue/types.d.ts.map +1 -0
  59. package/dist/client/adapters/vue/types.ts +85 -0
  60. package/dist/client/lib/activity/activity.class.d.ts +5 -5
  61. package/dist/client/lib/activity/activity.class.d.ts.map +1 -1
  62. package/dist/client/lib/user-cache.d.ts +39 -0
  63. package/dist/client/lib/user-cache.d.ts.map +1 -0
  64. package/dist/client/lib/user-cache.ts +168 -0
  65. package/dist/client/namespaces/activity.d.ts +2 -3
  66. package/dist/client/namespaces/activity.d.ts.map +1 -1
  67. package/dist/client.d.ts +1 -1
  68. package/dist/client.js +1 -257
  69. package/dist/edge.js +1 -86271
  70. package/dist/identity.js +1 -86131
  71. package/dist/index.js +22 -104883
  72. package/dist/server/adapters/express.js +1 -85973
  73. package/dist/server/adapters/native.js +2 -221
  74. package/dist/server/adapters/nextjs.js +1 -233
  75. package/dist/server/adapters/nuxt.js +1 -86046
  76. package/dist/server/adapters/solid-start.js +1 -85945
  77. package/dist/server/adapters/svelte-kit.js +1 -279
  78. package/dist/server/adapters/tanstack-start.js +1 -85918
  79. package/dist/server/handlers/activity/attempts.d.ts +51 -0
  80. package/dist/server/handlers/activity/attempts.d.ts.map +1 -0
  81. package/dist/server/handlers/activity/caliper.d.ts +46 -5
  82. package/dist/server/handlers/activity/caliper.d.ts.map +1 -1
  83. package/dist/server/handlers/activity/completion.d.ts +43 -0
  84. package/dist/server/handlers/activity/completion.d.ts.map +1 -0
  85. package/dist/server/handlers/activity/handler.d.ts +18 -1
  86. package/dist/server/handlers/activity/handler.d.ts.map +1 -1
  87. package/dist/server/handlers/activity/progress.d.ts +47 -0
  88. package/dist/server/handlers/activity/progress.d.ts.map +1 -0
  89. package/dist/server/handlers/activity/schema.d.ts +1 -2
  90. package/dist/server/handlers/activity/schema.d.ts.map +1 -1
  91. package/dist/server/handlers/activity/types.d.ts +1 -2
  92. package/dist/server/handlers/activity/types.d.ts.map +1 -1
  93. package/dist/server/lib/index.d.ts +1 -1
  94. package/dist/server/lib/index.d.ts.map +1 -1
  95. package/dist/server/lib/utils.d.ts +61 -0
  96. package/dist/server/lib/utils.d.ts.map +1 -1
  97. package/dist/server/timeback.d.ts.map +1 -1
  98. package/dist/server/types.d.ts +7 -1
  99. package/dist/server/types.d.ts.map +1 -1
  100. package/dist/shared/constants.d.ts +6 -0
  101. package/dist/shared/constants.d.ts.map +1 -1
  102. package/dist/shared/types.d.ts +62 -8
  103. package/dist/shared/types.d.ts.map +1 -1
  104. package/dist/shared/xp-calculator.d.ts +25 -0
  105. package/dist/shared/xp-calculator.d.ts.map +1 -0
  106. package/package.json +4 -2
  107. package/dist/client/adapters/svelte/stores.d.ts.map +0 -1
  108. package/dist/server/handlers/activity/gradebook.d.ts +0 -56
  109. package/dist/server/handlers/activity/gradebook.d.ts.map +0 -1
@@ -0,0 +1,209 @@
1
+ /**
2
+ * createTimebackProfile
3
+ *
4
+ * Solid primitive for fetching the current user's Timeback profile.
5
+ *
6
+ * Composes `createTimebackVerification` internally and only fetches
7
+ * the profile when the user is verified (i.e., exists in Timeback).
8
+ */
9
+
10
+ import { createEffect, createMemo, createSignal, onCleanup } from 'solid-js'
11
+
12
+ import { fetchProfileOnce, getProfileCache } from '../../../lib/user-cache'
13
+ import { useTimeback } from '../context'
14
+ import { createTimebackVerification } from './createTimebackVerification'
15
+
16
+ import type {
17
+ CreateTimebackProfileOptions,
18
+ CreateTimebackProfileResult,
19
+ TimebackProfileState,
20
+ } from '../types'
21
+
22
+ /**
23
+ * Fetch the current user's Timeback profile.
24
+ *
25
+ * Internally uses `createTimebackVerification` to ensure the user
26
+ * is verified before fetching. When `auto: true`, it automatically fetches
27
+ * the profile once verified. Otherwise, call `fetchProfile()` manually.
28
+ *
29
+ * @param options - Options
30
+ * @param options.enabled - If false, does nothing and stays in idle state. Defaults to true.
31
+ * @param options.auto - If true, automatically fetch once verified. Defaults to false.
32
+ * @returns Profile state and fetch methods
33
+ *
34
+ * @example
35
+ * ```tsx
36
+ * // Manual fetch
37
+ * import { createTimebackProfile } from '@timeback/sdk/solid'
38
+ * import { Show } from 'solid-js'
39
+ *
40
+ * function ProfileButton() {
41
+ * const { state, canFetch, fetchProfile } = createTimebackProfile()
42
+ *
43
+ * return (
44
+ * <Show
45
+ * when={state.status === 'loaded'}
46
+ * fallback={
47
+ * <button onClick={fetchProfile} disabled={!canFetch}>
48
+ * {state.status === 'loading' ? 'Loading...' : 'Load Profile'}
49
+ * </button>
50
+ * }
51
+ * >
52
+ * <div>XP: {state.profile.xp}</div>
53
+ * </Show>
54
+ * )
55
+ * }
56
+ *
57
+ * // Auto-fetch
58
+ * function AutoProfile() {
59
+ * const { state } = createTimebackProfile({ auto: true })
60
+ *
61
+ * return (
62
+ * <Show when={state.status === 'loading'}>
63
+ * <div>Loading...</div>
64
+ * </Show>
65
+ * )
66
+ * }
67
+ * ```
68
+ */
69
+ export function createTimebackProfile(
70
+ options: CreateTimebackProfileOptions = {},
71
+ ): CreateTimebackProfileResult {
72
+ const { enabled = true, auto = false } = options
73
+
74
+ const timeback = useTimeback()
75
+ const verification = createTimebackVerification({ enabled })
76
+
77
+ const [state, setState] = createSignal<TimebackProfileState>({ status: 'idle' })
78
+ const [fetchNonce, setFetchNonce] = createSignal(0)
79
+ const [refreshNonce, setRefreshNonce] = createSignal(0)
80
+
81
+ let lastHandledFetchNonce = 0
82
+ let lastHandledRefreshNonce = 0
83
+ let autoTriggered = false
84
+
85
+ const canFetch = createMemo(
86
+ () => enabled && verification.state.status === 'verified' && !!timeback,
87
+ )
88
+
89
+ const fetchProfile = () => {
90
+ if (!canFetch()) {
91
+ return
92
+ }
93
+
94
+ setFetchNonce(n => n + 1)
95
+ }
96
+
97
+ const refresh = () => {
98
+ if (!canFetch()) {
99
+ return
100
+ }
101
+
102
+ setRefreshNonce(n => n + 1)
103
+ }
104
+
105
+ createEffect(() => {
106
+ const verificationState = verification.state
107
+ const fetchN = fetchNonce()
108
+ const refreshN = refreshNonce()
109
+
110
+ if (!enabled) {
111
+ setState({ status: 'idle' })
112
+ return
113
+ }
114
+
115
+ if (verificationState.status !== 'verified') {
116
+ setState(current => (current.status === 'idle' ? current : { status: 'idle' }))
117
+ autoTriggered = false
118
+ return
119
+ }
120
+
121
+ if (auto && !autoTriggered && fetchN === 0 && refreshN === 0) {
122
+ autoTriggered = true
123
+ setFetchNonce(1)
124
+ return
125
+ }
126
+
127
+ if (fetchN === 0 && refreshN === 0) {
128
+ return
129
+ }
130
+
131
+ let cancelled = false
132
+ const isNewFetch = fetchN > lastHandledFetchNonce
133
+ const isNewRefresh = refreshN > lastHandledRefreshNonce
134
+ const force = isNewRefresh
135
+
136
+ if (!isNewFetch && !isNewRefresh) {
137
+ if (timeback) {
138
+ const cached = getProfileCache(timeback)
139
+
140
+ if (cached) {
141
+ setState({ status: 'loaded', profile: cached })
142
+ onCleanup(() => {
143
+ cancelled = true
144
+ })
145
+
146
+ return
147
+ }
148
+ }
149
+ return
150
+ }
151
+
152
+ if (timeback && !force) {
153
+ const cached = getProfileCache(timeback)
154
+
155
+ if (cached) {
156
+ setState({ status: 'loaded', profile: cached })
157
+ lastHandledFetchNonce = fetchN
158
+ onCleanup(() => {
159
+ cancelled = true
160
+ })
161
+
162
+ return
163
+ }
164
+ }
165
+
166
+ setState({ status: 'loading' })
167
+
168
+ void (async () => {
169
+ try {
170
+ if (!timeback) {
171
+ return
172
+ }
173
+
174
+ lastHandledFetchNonce = fetchN
175
+ lastHandledRefreshNonce = refreshN
176
+
177
+ const profile = await fetchProfileOnce(timeback, force)
178
+
179
+ if (cancelled) {
180
+ return
181
+ }
182
+
183
+ setState({ status: 'loaded', profile })
184
+ } catch (err) {
185
+ if (!cancelled) {
186
+ setState({
187
+ status: 'error',
188
+ message: err instanceof Error ? err.message : 'Failed to fetch profile',
189
+ })
190
+ }
191
+ }
192
+ })()
193
+
194
+ onCleanup(() => {
195
+ cancelled = true
196
+ })
197
+ })
198
+
199
+ return {
200
+ get state() {
201
+ return state()
202
+ },
203
+ get canFetch() {
204
+ return canFetch()
205
+ },
206
+ fetchProfile,
207
+ refresh,
208
+ }
209
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * createTimebackVerification
3
+ *
4
+ * Solid primitive for checking whether the current user can be verified in Timeback.
5
+ *
6
+ * This is a lightweight check (backed by `/api/timeback/user/verify`) and is
7
+ * intended for partner gating flows (e.g., "free for Timeback users").
8
+ */
9
+ import type { CreateTimebackVerificationOptions, CreateTimebackVerificationResult } from '../types';
10
+ /**
11
+ * Verify the current user against Timeback.
12
+ *
13
+ * Runs automatically once the Timeback client is available, and
14
+ * provides a `refresh()` method to retry.
15
+ *
16
+ * @param options - Options
17
+ * @param options.enabled - If false, does nothing and stays in loading state.
18
+ * @returns Verification state and a refresh method
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * import { createTimebackVerification } from '@timeback/sdk/solid'
23
+ *
24
+ * function VerificationGate() {
25
+ * const { state, refresh } = createTimebackVerification()
26
+ *
27
+ * return (
28
+ * <Show when={state().status === 'verified'}>
29
+ * <p>Verified as {state().timebackId}</p>
30
+ * </Show>
31
+ * )
32
+ * }
33
+ * ```
34
+ */
35
+ export declare function createTimebackVerification(options?: CreateTimebackVerificationOptions): CreateTimebackVerificationResult;
36
+ //# sourceMappingURL=createTimebackVerification.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTimebackVerification.d.ts","sourceRoot":"","sources":["../../../../../src/client/adapters/solid/primitives/createTimebackVerification.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH,OAAO,KAAK,EACX,iCAAiC,EACjC,gCAAgC,EAEhC,MAAM,UAAU,CAAA;AAcjB;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,GAAE,iCAAsC,GAC7C,gCAAgC,CAwElC"}
@@ -0,0 +1,133 @@
1
+ /**
2
+ * createTimebackVerification
3
+ *
4
+ * Solid primitive for checking whether the current user can be verified in Timeback.
5
+ *
6
+ * This is a lightweight check (backed by `/api/timeback/user/verify`) and is
7
+ * intended for partner gating flows (e.g., "free for Timeback users").
8
+ */
9
+
10
+ import { createEffect, createSignal, onCleanup } from 'solid-js'
11
+
12
+ import { getVerifyCache, verifyOnce } from '../../../lib/user-cache'
13
+ import { useTimeback } from '../context'
14
+
15
+ import type { TimebackVerifyResult } from '../../../../shared/types'
16
+ import type {
17
+ CreateTimebackVerificationOptions,
18
+ CreateTimebackVerificationResult,
19
+ TimebackVerificationState,
20
+ } from '../types'
21
+
22
+ /**
23
+ * Convert a verify result into a hook-friendly state machine.
24
+ *
25
+ * @param result - Raw verify result from the SDK client
26
+ * @returns Mapped verification state
27
+ */
28
+ function toState(result: TimebackVerifyResult): TimebackVerificationState {
29
+ return result.verified
30
+ ? { status: 'verified', timebackId: result.timebackId }
31
+ : { status: 'unverified' }
32
+ }
33
+
34
+ /**
35
+ * Verify the current user against Timeback.
36
+ *
37
+ * Runs automatically once the Timeback client is available, and
38
+ * provides a `refresh()` method to retry.
39
+ *
40
+ * @param options - Options
41
+ * @param options.enabled - If false, does nothing and stays in loading state.
42
+ * @returns Verification state and a refresh method
43
+ *
44
+ * @example
45
+ * ```tsx
46
+ * import { createTimebackVerification } from '@timeback/sdk/solid'
47
+ *
48
+ * function VerificationGate() {
49
+ * const { state, refresh } = createTimebackVerification()
50
+ *
51
+ * return (
52
+ * <Show when={state().status === 'verified'}>
53
+ * <p>Verified as {state().timebackId}</p>
54
+ * </Show>
55
+ * )
56
+ * }
57
+ * ```
58
+ */
59
+ export function createTimebackVerification(
60
+ options: CreateTimebackVerificationOptions = {},
61
+ ): CreateTimebackVerificationResult {
62
+ const enabled = options.enabled ?? true
63
+ const timeback = useTimeback()
64
+
65
+ const [state, setState] = createSignal<TimebackVerificationState>({ status: 'loading' })
66
+ const [refreshNonce, setRefreshNonce] = createSignal(0)
67
+
68
+ const refresh = () => {
69
+ if (!enabled) return
70
+ setRefreshNonce(n => n + 1)
71
+ }
72
+
73
+ let lastHandledRefreshNonce = 0
74
+
75
+ createEffect(() => {
76
+ if (!enabled) return
77
+
78
+ const nonce = refreshNonce()
79
+ const client = timeback
80
+
81
+ let cancelled = false
82
+ const force = nonce > lastHandledRefreshNonce
83
+
84
+ if (client && !force) {
85
+ const cached = getVerifyCache(client)
86
+
87
+ if (cached) {
88
+ setState(toState(cached))
89
+ onCleanup(() => {
90
+ cancelled = true
91
+ })
92
+ return
93
+ }
94
+ }
95
+
96
+ setState({ status: 'loading' })
97
+
98
+ void (async () => {
99
+ try {
100
+ if (!client) return
101
+
102
+ if (force) {
103
+ lastHandledRefreshNonce = nonce
104
+ }
105
+
106
+ const result = await verifyOnce(client, force)
107
+
108
+ if (cancelled) return
109
+
110
+ setState(toState(result))
111
+ } catch (err) {
112
+ if (!cancelled) {
113
+ setState({
114
+ status: 'error',
115
+ message:
116
+ err instanceof Error ? err.message : 'Failed to verify Timeback user',
117
+ })
118
+ }
119
+ }
120
+ })()
121
+
122
+ onCleanup(() => {
123
+ cancelled = true
124
+ })
125
+ })
126
+
127
+ return {
128
+ get state() {
129
+ return state()
130
+ },
131
+ refresh,
132
+ }
133
+ }
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Solid Types
3
+ *
4
+ * Types for Solid-specific primitives.
5
+ */
6
+ import type { TimebackProfile } from '../../../shared/types';
7
+ /**
8
+ * Verification state for the current user.
9
+ */
10
+ export type TimebackVerificationState = {
11
+ status: 'loading';
12
+ } | {
13
+ status: 'verified';
14
+ timebackId: string;
15
+ } | {
16
+ status: 'unverified';
17
+ } | {
18
+ status: 'error';
19
+ message: string;
20
+ };
21
+ /**
22
+ * Profile state for the current user.
23
+ */
24
+ export type TimebackProfileState = {
25
+ status: 'idle';
26
+ } | {
27
+ status: 'loading';
28
+ } | {
29
+ status: 'loaded';
30
+ profile: TimebackProfile;
31
+ } | {
32
+ status: 'error';
33
+ message: string;
34
+ };
35
+ /**
36
+ * Options for createTimebackVerification.
37
+ */
38
+ export interface CreateTimebackVerificationOptions {
39
+ /**
40
+ * If false, does nothing and stays in loading state.
41
+ *
42
+ * @default true
43
+ */
44
+ enabled?: boolean;
45
+ }
46
+ /**
47
+ * Return value of createTimebackVerification.
48
+ */
49
+ export interface CreateTimebackVerificationResult {
50
+ /** Current verification state */
51
+ state: TimebackVerificationState;
52
+ /** Force a re-verification. No-op if not enabled. */
53
+ refresh: () => void;
54
+ }
55
+ /**
56
+ * Options for createTimebackProfile.
57
+ */
58
+ export interface CreateTimebackProfileOptions {
59
+ /**
60
+ * If false, does nothing and stays in idle state.
61
+ *
62
+ * @default true
63
+ */
64
+ enabled?: boolean;
65
+ /**
66
+ * If true, automatically fetch the profile once the user is verified.
67
+ * If false, you must call `fetchProfile()` manually.
68
+ *
69
+ * @default false
70
+ */
71
+ auto?: boolean;
72
+ }
73
+ /**
74
+ * Return value of createTimebackProfile.
75
+ */
76
+ export interface CreateTimebackProfileResult {
77
+ /** Current profile state */
78
+ state: TimebackProfileState;
79
+ /** Whether the profile can be fetched (user is verified and client is ready) */
80
+ canFetch: boolean;
81
+ /** Manually trigger a profile fetch. No-op if canFetch is false. */
82
+ fetchProfile: () => void;
83
+ /** Force a re-fetch even if already loaded. No-op if canFetch is false. */
84
+ refresh: () => void;
85
+ }
86
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/client/adapters/solid/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAE5D;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAClC;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,MAAM,EAAE,YAAY,CAAA;CAAE,GACxB;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvC;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAC7B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,GAC9C;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvC;;GAEG;AACH,MAAM,WAAW,iCAAiC;IACjD;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gCAAgC;IAChD,iCAAiC;IACjC,KAAK,EAAE,yBAAyB,CAAA;IAEhC,qDAAqD;IACrD,OAAO,EAAE,MAAM,IAAI,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC5C;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;;OAKG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC3C,4BAA4B;IAC5B,KAAK,EAAE,oBAAoB,CAAA;IAE3B,gFAAgF;IAChF,QAAQ,EAAE,OAAO,CAAA;IAEjB,oEAAoE;IACpE,YAAY,EAAE,MAAM,IAAI,CAAA;IAExB,2EAA2E;IAC3E,OAAO,EAAE,MAAM,IAAI,CAAA;CACnB"}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Solid Types
3
+ *
4
+ * Types for Solid-specific primitives.
5
+ */
6
+
7
+ import type { TimebackProfile } from '../../../shared/types'
8
+
9
+ /**
10
+ * Verification state for the current user.
11
+ */
12
+ export type TimebackVerificationState =
13
+ | { status: 'loading' }
14
+ | { status: 'verified'; timebackId: string }
15
+ | { status: 'unverified' }
16
+ | { status: 'error'; message: string }
17
+
18
+ /**
19
+ * Profile state for the current user.
20
+ */
21
+ export type TimebackProfileState =
22
+ | { status: 'idle' }
23
+ | { status: 'loading' }
24
+ | { status: 'loaded'; profile: TimebackProfile }
25
+ | { status: 'error'; message: string }
26
+
27
+ /**
28
+ * Options for createTimebackVerification.
29
+ */
30
+ export interface CreateTimebackVerificationOptions {
31
+ /**
32
+ * If false, does nothing and stays in loading state.
33
+ *
34
+ * @default true
35
+ */
36
+ enabled?: boolean
37
+ }
38
+
39
+ /**
40
+ * Return value of createTimebackVerification.
41
+ */
42
+ export interface CreateTimebackVerificationResult {
43
+ /** Current verification state */
44
+ state: TimebackVerificationState
45
+
46
+ /** Force a re-verification. No-op if not enabled. */
47
+ refresh: () => void
48
+ }
49
+
50
+ /**
51
+ * Options for createTimebackProfile.
52
+ */
53
+ export interface CreateTimebackProfileOptions {
54
+ /**
55
+ * If false, does nothing and stays in idle state.
56
+ *
57
+ * @default true
58
+ */
59
+ enabled?: boolean
60
+
61
+ /**
62
+ * If true, automatically fetch the profile once the user is verified.
63
+ * If false, you must call `fetchProfile()` manually.
64
+ *
65
+ * @default false
66
+ */
67
+ auto?: boolean
68
+ }
69
+
70
+ /**
71
+ * Return value of createTimebackProfile.
72
+ */
73
+ export interface CreateTimebackProfileResult {
74
+ /** Current profile state */
75
+ state: TimebackProfileState
76
+
77
+ /** Whether the profile can be fetched (user is verified and client is ready) */
78
+ canFetch: boolean
79
+
80
+ /** Manually trigger a profile fetch. No-op if canFetch is false. */
81
+ fetchProfile: () => void
82
+
83
+ /** Force a re-fetch even if already loaded. No-op if canFetch is false. */
84
+ refresh: () => void
85
+ }
@@ -30,7 +30,8 @@
30
30
  */
31
31
  export { Activity, createClient, TimebackClient } from '@timeback/sdk/client';
32
32
  export type { ActivityMetrics, ActivityParams, TimebackIdentity } from '@timeback/sdk/client';
33
- export { initTimeback, timeback } from './stores';
33
+ export { fetchTimebackProfile, initTimeback, refreshTimebackProfile, refreshTimebackVerification, timeback, timebackProfile, timebackProfileCanFetch, timebackVerification, } from './stores';
34
+ export type { TimebackProfileState, TimebackVerificationState } from './stores';
34
35
  export { default as SignInButton } from './SignInButton.svelte';
35
36
  export type { SignInButtonProps } from './SignInButton.svelte';
36
37
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/adapters/svelte/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAGH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC7E,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG7F,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/client/adapters/svelte/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC7E,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAG7F,OAAO,EACN,oBAAoB,EACpB,YAAY,EACZ,sBAAsB,EACtB,2BAA2B,EAC3B,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,oBAAoB,GACpB,MAAM,UAAU,CAAA;AACjB,YAAY,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA;AAG/E,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAC/D,YAAY,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA"}
@@ -29,12 +29,21 @@
29
29
  * ```
30
30
  */
31
31
 
32
- // Re-export from timeback/client for convenience
33
32
  export { Activity, createClient, TimebackClient } from '@timeback/sdk/client'
34
33
  export type { ActivityMetrics, ActivityParams, TimebackIdentity } from '@timeback/sdk/client'
35
34
 
36
35
  // Svelte-specific
37
- export { initTimeback, timeback } from './stores'
36
+ export {
37
+ fetchTimebackProfile,
38
+ initTimeback,
39
+ refreshTimebackProfile,
40
+ refreshTimebackVerification,
41
+ timeback,
42
+ timebackProfile,
43
+ timebackProfileCanFetch,
44
+ timebackVerification,
45
+ } from './stores'
46
+ export type { TimebackProfileState, TimebackVerificationState } from './stores'
38
47
 
39
48
  // Components
40
49
  export { default as SignInButton } from './SignInButton.svelte'
@@ -1,17 +1,20 @@
1
1
  /**
2
- * Svelte Stores
2
+ * Timeback Client Store
3
3
  *
4
- * Svelte stores for Timeback SDK reactivity.
4
+ * Core Svelte store for the Timeback client singleton.
5
5
  */
6
6
  import { TimebackClient } from '@timeback/sdk/client';
7
+ import type { Readable } from 'svelte/store';
7
8
  /**
8
- * Minimal Svelte-compatible store interface.
9
+ * Internal client store.
10
+ */
11
+ export declare const clientStore: import("svelte/store").Writable<TimebackClient | undefined>;
12
+ /**
13
+ * Get the current client instance (for internal use by other stores).
9
14
  *
10
- * This allows the SDK to work without a direct Svelte dependency.
15
+ * @returns Current client instance or undefined
11
16
  */
12
- interface Readable<T> {
13
- subscribe: (run: (value: T) => void) => () => void;
14
- }
17
+ export declare function getClientInstance(): TimebackClient | undefined;
15
18
  /**
16
19
  * Initialize the Timeback client.
17
20
  *
@@ -61,5 +64,4 @@ export declare function initTimeback(client?: TimebackClient): void;
61
64
  * ```
62
65
  */
63
66
  export declare const timeback: Readable<TimebackClient | undefined>;
64
- export {};
65
- //# sourceMappingURL=stores.d.ts.map
67
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../../src/client/adapters/svelte/stores/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAErD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAyB5C;;GAEG;AACH,eAAO,MAAM,WAAW,6DAAkD,CAAA;AAE1E;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,cAAc,GAAG,SAAS,CAE9D;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAQ1D;AASD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,cAAc,GAAG,SAAS,CAAe,CAAA"}