@timeback/sdk 0.1.6 → 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 (186) 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 +61 -0
  13. package/dist/client/adapters/react/hooks/types.d.ts.map +1 -0
  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/hooks/useTimebackVerification.d.ts +18 -0
  17. package/dist/client/adapters/react/hooks/useTimebackVerification.d.ts.map +1 -0
  18. package/dist/client/adapters/react/index.d.ts +3 -0
  19. package/dist/client/adapters/react/index.d.ts.map +1 -1
  20. package/dist/client/adapters/react/index.js +2 -364
  21. package/dist/client/adapters/solid/index.d.ts +3 -0
  22. package/dist/client/adapters/solid/index.d.ts.map +1 -1
  23. package/dist/client/adapters/solid/index.ts +12 -0
  24. package/dist/client/adapters/solid/primitives/createTimebackProfile.d.ts +58 -0
  25. package/dist/client/adapters/solid/primitives/createTimebackProfile.d.ts.map +1 -0
  26. package/dist/client/adapters/solid/primitives/createTimebackProfile.ts +209 -0
  27. package/dist/client/adapters/solid/primitives/createTimebackVerification.d.ts +36 -0
  28. package/dist/client/adapters/solid/primitives/createTimebackVerification.d.ts.map +1 -0
  29. package/dist/client/adapters/solid/primitives/createTimebackVerification.ts +133 -0
  30. package/dist/client/adapters/solid/types.d.ts +86 -0
  31. package/dist/client/adapters/solid/types.d.ts.map +1 -0
  32. package/dist/client/adapters/solid/types.ts +85 -0
  33. package/dist/client/adapters/svelte/index.d.ts +2 -1
  34. package/dist/client/adapters/svelte/index.d.ts.map +1 -1
  35. package/dist/client/adapters/svelte/index.ts +11 -2
  36. package/dist/client/adapters/svelte/{stores.d.ts → stores/client.d.ts} +11 -9
  37. package/dist/client/adapters/svelte/stores/client.d.ts.map +1 -0
  38. package/dist/client/adapters/svelte/{stores.ts → stores/client.ts} +24 -52
  39. package/dist/client/adapters/svelte/stores/index.d.ts +10 -0
  40. package/dist/client/adapters/svelte/stores/index.d.ts.map +1 -0
  41. package/dist/client/adapters/svelte/stores/index.ts +22 -0
  42. package/dist/client/adapters/svelte/stores/profile.d.ts +66 -0
  43. package/dist/client/adapters/svelte/stores/profile.d.ts.map +1 -0
  44. package/dist/client/adapters/svelte/stores/profile.ts +168 -0
  45. package/dist/client/adapters/svelte/stores/verification.d.ts +43 -0
  46. package/dist/client/adapters/svelte/stores/verification.d.ts.map +1 -0
  47. package/dist/client/adapters/svelte/stores/verification.ts +126 -0
  48. package/dist/client/adapters/svelte/types.d.ts +35 -0
  49. package/dist/client/adapters/svelte/types.d.ts.map +1 -0
  50. package/dist/client/adapters/vue/composables/useTimebackProfile.d.ts +51 -0
  51. package/dist/client/adapters/vue/composables/useTimebackProfile.d.ts.map +1 -0
  52. package/dist/client/adapters/vue/composables/useTimebackProfile.ts +186 -0
  53. package/dist/client/adapters/vue/composables/useTimebackVerification.d.ts +44 -0
  54. package/dist/client/adapters/vue/composables/useTimebackVerification.d.ts.map +1 -0
  55. package/dist/client/adapters/vue/composables/useTimebackVerification.ts +128 -0
  56. package/dist/client/adapters/vue/index.d.ts +3 -0
  57. package/dist/client/adapters/vue/index.d.ts.map +1 -1
  58. package/dist/client/adapters/vue/index.ts +12 -1
  59. package/dist/client/adapters/vue/types.d.ts +86 -0
  60. package/dist/client/adapters/vue/types.d.ts.map +1 -0
  61. package/dist/client/adapters/vue/types.ts +85 -0
  62. package/dist/client/auth/bearer.d.ts +17 -0
  63. package/dist/client/auth/bearer.d.ts.map +1 -0
  64. package/dist/client/auth/index.d.ts +3 -0
  65. package/dist/client/auth/index.d.ts.map +1 -0
  66. package/dist/client/auth/types.d.ts +39 -0
  67. package/dist/client/auth/types.d.ts.map +1 -0
  68. package/dist/client/index.d.ts +2 -0
  69. package/dist/client/index.d.ts.map +1 -1
  70. package/dist/client/lib/activity/activity.class.d.ts +5 -5
  71. package/dist/client/lib/activity/activity.class.d.ts.map +1 -1
  72. package/dist/client/lib/fetch.d.ts +19 -0
  73. package/dist/client/lib/fetch.d.ts.map +1 -0
  74. package/dist/client/lib/user-cache.d.ts +39 -0
  75. package/dist/client/lib/user-cache.d.ts.map +1 -0
  76. package/dist/client/lib/user-cache.ts +168 -0
  77. package/dist/client/namespaces/activity.d.ts +2 -3
  78. package/dist/client/namespaces/activity.d.ts.map +1 -1
  79. package/dist/client/namespaces/user.d.ts +25 -2
  80. package/dist/client/namespaces/user.d.ts.map +1 -1
  81. package/dist/client/timeback-client.class.d.ts +15 -0
  82. package/dist/client/timeback-client.class.d.ts.map +1 -1
  83. package/dist/client/timeback-client.d.ts +3 -0
  84. package/dist/client/timeback-client.d.ts.map +1 -1
  85. package/dist/client.d.ts +3 -2
  86. package/dist/client.d.ts.map +1 -1
  87. package/dist/client.js +1 -194
  88. package/dist/edge.js +1 -1149
  89. package/dist/identity.js +1 -1019
  90. package/dist/index.js +22 -104603
  91. package/dist/server/adapters/express.d.ts.map +1 -1
  92. package/dist/server/adapters/express.js +1 -85997
  93. package/dist/server/adapters/native.d.ts.map +1 -1
  94. package/dist/server/adapters/native.js +2 -190
  95. package/dist/server/adapters/nextjs.js +1 -202
  96. package/dist/server/adapters/nuxt.d.ts.map +1 -1
  97. package/dist/server/adapters/nuxt.js +1 -86066
  98. package/dist/server/adapters/solid-start.d.ts.map +1 -1
  99. package/dist/server/adapters/solid-start.js +1 -85965
  100. package/dist/server/adapters/svelte-kit.d.ts.map +1 -1
  101. package/dist/server/adapters/svelte-kit.js +1 -243
  102. package/dist/server/adapters/tanstack-start.d.ts.map +1 -1
  103. package/dist/server/adapters/tanstack-start.js +1 -85943
  104. package/dist/server/adapters/utils.d.ts +1 -1
  105. package/dist/server/adapters/utils.d.ts.map +1 -1
  106. package/dist/server/handlers/activity/attempts.d.ts +51 -0
  107. package/dist/server/handlers/activity/attempts.d.ts.map +1 -0
  108. package/dist/server/handlers/activity/caliper.d.ts +133 -0
  109. package/dist/server/handlers/activity/caliper.d.ts.map +1 -0
  110. package/dist/server/handlers/activity/completion.d.ts +43 -0
  111. package/dist/server/handlers/activity/completion.d.ts.map +1 -0
  112. package/dist/server/handlers/activity/handler.d.ts +32 -0
  113. package/dist/server/handlers/activity/handler.d.ts.map +1 -0
  114. package/dist/server/handlers/activity/index.d.ts +9 -0
  115. package/dist/server/handlers/activity/index.d.ts.map +1 -0
  116. package/dist/server/handlers/activity/progress.d.ts +47 -0
  117. package/dist/server/handlers/activity/progress.d.ts.map +1 -0
  118. package/dist/server/handlers/activity/resolve.d.ts +39 -0
  119. package/dist/server/handlers/activity/resolve.d.ts.map +1 -0
  120. package/dist/server/handlers/activity/schema.d.ts +51 -0
  121. package/dist/server/handlers/activity/schema.d.ts.map +1 -0
  122. package/dist/server/handlers/activity/types.d.ts +51 -0
  123. package/dist/server/handlers/activity/types.d.ts.map +1 -0
  124. package/dist/server/handlers/identity/handler.d.ts +14 -0
  125. package/dist/server/handlers/identity/handler.d.ts.map +1 -0
  126. package/dist/server/handlers/identity/index.d.ts +8 -0
  127. package/dist/server/handlers/identity/index.d.ts.map +1 -0
  128. package/dist/server/handlers/identity/oidc.d.ts +43 -0
  129. package/dist/server/handlers/identity/oidc.d.ts.map +1 -0
  130. package/dist/server/handlers/identity/types.d.ts +24 -0
  131. package/dist/server/handlers/identity/types.d.ts.map +1 -0
  132. package/dist/server/handlers/identity-only/handler.d.ts +15 -0
  133. package/dist/server/handlers/identity-only/handler.d.ts.map +1 -0
  134. package/dist/server/handlers/identity-only/index.d.ts +8 -0
  135. package/dist/server/handlers/identity-only/index.d.ts.map +1 -0
  136. package/dist/server/handlers/identity-only/oidc.d.ts +26 -0
  137. package/dist/server/handlers/identity-only/oidc.d.ts.map +1 -0
  138. package/dist/server/handlers/identity-only/types.d.ts +19 -0
  139. package/dist/server/handlers/identity-only/types.d.ts.map +1 -0
  140. package/dist/server/handlers/index.d.ts +5 -2
  141. package/dist/server/handlers/index.d.ts.map +1 -1
  142. package/dist/server/{lib/build-user-profile.d.ts → handlers/user/enrollments.d.ts} +7 -2
  143. package/dist/server/handlers/user/enrollments.d.ts.map +1 -0
  144. package/dist/server/handlers/user/handler.d.ts +17 -0
  145. package/dist/server/handlers/user/handler.d.ts.map +1 -0
  146. package/dist/server/handlers/user/index.d.ts +10 -0
  147. package/dist/server/handlers/user/index.d.ts.map +1 -0
  148. package/dist/server/handlers/user/profile.d.ts +22 -0
  149. package/dist/server/handlers/user/profile.d.ts.map +1 -0
  150. package/dist/server/handlers/user/types.d.ts +35 -0
  151. package/dist/server/handlers/user/types.d.ts.map +1 -0
  152. package/dist/server/handlers/user/verify.d.ts +25 -0
  153. package/dist/server/handlers/user/verify.d.ts.map +1 -0
  154. package/dist/server/index.d.ts +1 -1
  155. package/dist/server/index.d.ts.map +1 -1
  156. package/dist/server/lib/index.d.ts +4 -5
  157. package/dist/server/lib/index.d.ts.map +1 -1
  158. package/dist/server/lib/resolve.d.ts +4 -42
  159. package/dist/server/lib/resolve.d.ts.map +1 -1
  160. package/dist/server/lib/sso.d.ts +86 -0
  161. package/dist/server/lib/sso.d.ts.map +1 -0
  162. package/dist/server/lib/utils.d.ts +93 -1
  163. package/dist/server/lib/utils.d.ts.map +1 -1
  164. package/dist/server/timeback-identity.d.ts.map +1 -1
  165. package/dist/server/timeback.d.ts.map +1 -1
  166. package/dist/server/types.d.ts +23 -10
  167. package/dist/server/types.d.ts.map +1 -1
  168. package/dist/shared/constants.d.ts +7 -0
  169. package/dist/shared/constants.d.ts.map +1 -1
  170. package/dist/shared/types.d.ts +77 -8
  171. package/dist/shared/types.d.ts.map +1 -1
  172. package/dist/shared/xp-calculator.d.ts +25 -0
  173. package/dist/shared/xp-calculator.d.ts.map +1 -0
  174. package/package.json +8 -2
  175. package/dist/client/adapters/svelte/stores.d.ts.map +0 -1
  176. package/dist/server/handlers/activity.d.ts +0 -25
  177. package/dist/server/handlers/activity.d.ts.map +0 -1
  178. package/dist/server/handlers/identity-full.d.ts +0 -28
  179. package/dist/server/handlers/identity-full.d.ts.map +0 -1
  180. package/dist/server/handlers/identity-only.d.ts +0 -22
  181. package/dist/server/handlers/identity-only.d.ts.map +0 -1
  182. package/dist/server/handlers/user.d.ts +0 -31
  183. package/dist/server/handlers/user.d.ts.map +0 -1
  184. package/dist/server/lib/build-activity-events.d.ts +0 -67
  185. package/dist/server/lib/build-activity-events.d.ts.map +0 -1
  186. package/dist/server/lib/build-user-profile.d.ts.map +0 -1
@@ -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"}
@@ -1,51 +1,14 @@
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
 
7
- import { TimebackClient } from '@timeback/sdk/client'
8
-
9
- /**
10
- * Minimal Svelte-compatible store interface.
11
- *
12
- * This allows the SDK to work without a direct Svelte dependency.
13
- */
14
- interface Readable<T> {
15
- subscribe: (run: (value: T) => void) => () => void
16
- }
17
-
18
- interface Writable<T> extends Readable<T> {
19
- set: (value: T) => void
20
- update: (updater: (value: T) => T) => void
21
- }
7
+ import { writable } from 'svelte/store'
22
8
 
23
- /**
24
- * Create a minimal writable store implementation.
25
- *
26
- * @param initialValue - Initial store value
27
- * @returns Writable store
28
- */
29
- function writable<T>(initialValue: T): Writable<T> {
30
- let value = initialValue
31
- const subscribers = new Set<(value: T) => void>()
9
+ import { TimebackClient } from '@timeback/sdk/client'
32
10
 
33
- return {
34
- subscribe(run) {
35
- subscribers.add(run)
36
- run(value)
37
- return () => subscribers.delete(run)
38
- },
39
- set(newValue) {
40
- value = newValue
41
- subscribers.forEach(fn => fn(value))
42
- },
43
- update(updater) {
44
- value = updater(value)
45
- subscribers.forEach(fn => fn(value))
46
- },
47
- }
48
- }
11
+ import type { Readable } from 'svelte/store'
49
12
 
50
13
  let clientInstance: TimebackClient | undefined
51
14
 
@@ -61,10 +24,28 @@ function getOrCreateClient(): TimebackClient {
61
24
  return clientInstance
62
25
  }
63
26
 
27
+ /**
28
+ * Check if we're running in the browser.
29
+ *
30
+ * @returns True if in browser
31
+ */
32
+ function isBrowser(): boolean {
33
+ return typeof window !== 'undefined'
34
+ }
35
+
64
36
  /**
65
37
  * Internal client store.
66
38
  */
67
- const clientStore = writable<TimebackClient | undefined>(undefined)
39
+ export const clientStore = writable<TimebackClient | undefined>(undefined)
40
+
41
+ /**
42
+ * Get the current client instance (for internal use by other stores).
43
+ *
44
+ * @returns Current client instance or undefined
45
+ */
46
+ export function getClientInstance(): TimebackClient | undefined {
47
+ return clientInstance
48
+ }
68
49
 
69
50
  /**
70
51
  * Initialize the Timeback client.
@@ -95,15 +76,6 @@ export function initTimeback(client?: TimebackClient): void {
95
76
  clientStore.set(getOrCreateClient())
96
77
  }
97
78
 
98
- /**
99
- * Check if we're running in the browser.
100
- *
101
- * @returns True if in browser
102
- */
103
- function isBrowser(): boolean {
104
- return typeof window !== 'undefined'
105
- }
106
-
107
79
  /**
108
80
  * Auto-initialize on first access in browser.
109
81
  */
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Svelte Stores
3
+ *
4
+ * Svelte stores for Timeback SDK reactivity.
5
+ */
6
+ export { initTimeback, timeback } from './client';
7
+ export { refreshTimebackVerification, timebackVerification } from './verification';
8
+ export { fetchTimebackProfile, refreshTimebackProfile, timebackProfile, timebackProfileCanFetch, } from './profile';
9
+ export type { TimebackProfileState, TimebackVerificationState } from '../types';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/client/adapters/svelte/stores/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAGjD,OAAO,EAAE,2BAA2B,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAGlF,OAAO,EACN,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,uBAAuB,GACvB,MAAM,WAAW,CAAA;AAGlB,YAAY,EAAE,oBAAoB,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Svelte Stores
3
+ *
4
+ * Svelte stores for Timeback SDK reactivity.
5
+ */
6
+
7
+ // Client
8
+ export { initTimeback, timeback } from './client'
9
+
10
+ // Verification
11
+ export { refreshTimebackVerification, timebackVerification } from './verification'
12
+
13
+ // Profile
14
+ export {
15
+ fetchTimebackProfile,
16
+ refreshTimebackProfile,
17
+ timebackProfile,
18
+ timebackProfileCanFetch,
19
+ } from './profile'
20
+
21
+ // Types re-exported for convenience
22
+ export type { TimebackProfileState, TimebackVerificationState } from '../types'
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Timeback Profile Store
3
+ *
4
+ * Svelte store for user profile state.
5
+ */
6
+ import type { TimebackProfileState } from '../types';
7
+ import type { Readable } from 'svelte/store';
8
+ /**
9
+ * Store containing the Timeback profile state.
10
+ *
11
+ * Use this to access the current user's Timeback profile.
12
+ * Call `fetchTimebackProfile()` to manually fetch, or `refreshTimebackProfile()` to force re-fetch.
13
+ *
14
+ * @example
15
+ * ```svelte
16
+ * <script>
17
+ * import { timebackProfile, timebackProfileCanFetch, fetchTimebackProfile } from '@timeback/sdk/svelte'
18
+ * </script>
19
+ *
20
+ * <button on:click={fetchTimebackProfile} disabled={!$timebackProfileCanFetch}>
21
+ * {$timebackProfile.status === 'loading' ? 'Loading...' : 'Fetch Profile'}
22
+ * </button>
23
+ *
24
+ * {#if $timebackProfile.status === 'loaded'}
25
+ * <pre>{JSON.stringify($timebackProfile.profile, null, 2)}</pre>
26
+ * {/if}
27
+ * ```
28
+ */
29
+ export declare const timebackProfile: Readable<TimebackProfileState>;
30
+ /**
31
+ * Store indicating whether the profile can be fetched.
32
+ *
33
+ * True when the user is verified and the client is ready.
34
+ */
35
+ export declare const timebackProfileCanFetch: Readable<boolean>;
36
+ /**
37
+ * Manually fetch the Timeback profile.
38
+ *
39
+ * No-op if the user is not verified or client is not ready.
40
+ *
41
+ * @example
42
+ * ```svelte
43
+ * <script>
44
+ * import { fetchTimebackProfile } from '@timeback/sdk/svelte'
45
+ * </script>
46
+ *
47
+ * <button on:click={fetchTimebackProfile}>Fetch Profile</button>
48
+ * ```
49
+ */
50
+ export declare function fetchTimebackProfile(): void;
51
+ /**
52
+ * Force a re-fetch of the Timeback profile.
53
+ *
54
+ * No-op if the user is not verified or client is not ready.
55
+ *
56
+ * @example
57
+ * ```svelte
58
+ * <script>
59
+ * import { refreshTimebackProfile } from '@timeback/sdk/svelte'
60
+ * </script>
61
+ *
62
+ * <button on:click={refreshTimebackProfile}>Refresh Profile</button>
63
+ * ```
64
+ */
65
+ export declare function refreshTimebackProfile(): void;
66
+ //# sourceMappingURL=profile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"profile.d.ts","sourceRoot":"","sources":["../../../../../src/client/adapters/svelte/stores/profile.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,KAAK,EAAE,oBAAoB,EAA6B,MAAM,UAAU,CAAA;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AA6E5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,oBAAoB,CAAgB,CAAA;AAE3E;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAAC,OAAO,CAAiB,CAAA;AAEvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAS3C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAS7C"}