usebecky 0.0.0-stage → 0.2.0

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 (135) hide show
  1. package/README.md +701 -2
  2. package/dist/analytics/client.d.ts +219 -0
  3. package/dist/analytics/client.js +923 -0
  4. package/dist/analytics/cmp.d.ts +20 -0
  5. package/dist/analytics/cmp.js +166 -0
  6. package/dist/analytics/context.d.ts +29 -0
  7. package/dist/analytics/context.js +97 -0
  8. package/dist/auth/client.d.ts +401 -0
  9. package/dist/auth/client.js +1081 -0
  10. package/dist/auth/webauthn.d.ts +18 -0
  11. package/dist/auth/webauthn.js +138 -0
  12. package/dist/cli/ai.d.ts +54 -0
  13. package/dist/cli/ai.js +202 -0
  14. package/dist/cli/analytics.d.ts +53 -0
  15. package/dist/cli/analytics.js +357 -0
  16. package/dist/cli/config.d.ts +75 -0
  17. package/dist/cli/config.js +718 -0
  18. package/dist/cli/db.d.ts +48 -0
  19. package/dist/cli/db.js +215 -0
  20. package/dist/cli/deploy-api.d.ts +168 -0
  21. package/dist/cli/deploy-api.js +177 -0
  22. package/dist/cli/deploy-ci.d.ts +15 -0
  23. package/dist/cli/deploy-ci.js +54 -0
  24. package/dist/cli/deploy-detect.d.ts +64 -0
  25. package/dist/cli/deploy-detect.js +249 -0
  26. package/dist/cli/deploy-files.d.ts +112 -0
  27. package/dist/cli/deploy-files.js +778 -0
  28. package/dist/cli/deploy.d.ts +10 -0
  29. package/dist/cli/deploy.js +430 -0
  30. package/dist/cli/emails.d.ts +29 -0
  31. package/dist/cli/emails.js +122 -0
  32. package/dist/cli/framework.d.ts +135 -0
  33. package/dist/cli/framework.js +459 -0
  34. package/dist/cli/functions.d.ts +59 -0
  35. package/dist/cli/functions.js +426 -0
  36. package/dist/cli/hosting.d.ts +4 -0
  37. package/dist/cli/hosting.js +532 -0
  38. package/dist/cli/index.d.ts +2 -0
  39. package/dist/cli/index.js +9 -0
  40. package/dist/cli/payments.d.ts +35 -0
  41. package/dist/cli/payments.js +176 -0
  42. package/dist/cli/push.d.ts +36 -0
  43. package/dist/cli/push.js +172 -0
  44. package/dist/cli/run.d.ts +65 -0
  45. package/dist/cli/run.js +850 -0
  46. package/dist/cli/social.d.ts +52 -0
  47. package/dist/cli/social.js +532 -0
  48. package/dist/cli/tokens.d.ts +28 -0
  49. package/dist/cli/tokens.js +114 -0
  50. package/dist/cli/ui.d.ts +38 -0
  51. package/dist/cli/ui.js +140 -0
  52. package/dist/client.d.ts +94 -0
  53. package/dist/client.js +156 -0
  54. package/dist/db/query.d.ts +162 -0
  55. package/dist/db/query.js +336 -0
  56. package/dist/db/types.d.ts +93 -0
  57. package/dist/db/types.js +4 -0
  58. package/dist/forms/client.d.ts +65 -0
  59. package/dist/forms/client.js +106 -0
  60. package/dist/functions/client.d.ts +37 -0
  61. package/dist/functions/client.js +76 -0
  62. package/dist/index.d.ts +17 -0
  63. package/dist/index.js +16 -0
  64. package/dist/lib/dashboard-paths.d.ts +4 -0
  65. package/dist/lib/dashboard-paths.js +8 -0
  66. package/dist/lib/env.d.ts +9 -0
  67. package/dist/lib/env.js +55 -0
  68. package/dist/lib/errors.d.ts +22 -0
  69. package/dist/lib/errors.js +90 -0
  70. package/dist/lib/hosted.d.ts +2 -0
  71. package/dist/lib/hosted.js +7 -0
  72. package/dist/lib/http.d.ts +59 -0
  73. package/dist/lib/http.js +172 -0
  74. package/dist/lib/jwt.d.ts +1 -0
  75. package/dist/lib/jwt.js +31 -0
  76. package/dist/lib/locale.d.ts +12 -0
  77. package/dist/lib/locale.js +51 -0
  78. package/dist/lib/pkce.d.ts +20 -0
  79. package/dist/lib/pkce.js +124 -0
  80. package/dist/lib/storage-adapter.d.ts +15 -0
  81. package/dist/lib/storage-adapter.js +91 -0
  82. package/dist/lib/types.d.ts +339 -0
  83. package/dist/lib/types.js +1 -0
  84. package/dist/newsletter/client.d.ts +140 -0
  85. package/dist/newsletter/client.js +85 -0
  86. package/dist/payments/client.d.ts +352 -0
  87. package/dist/payments/client.js +323 -0
  88. package/dist/push/client.d.ts +110 -0
  89. package/dist/push/client.js +179 -0
  90. package/dist/realtime/client.d.ts +131 -0
  91. package/dist/realtime/client.js +513 -0
  92. package/dist/server/analytics.d.ts +176 -0
  93. package/dist/server/analytics.js +49 -0
  94. package/dist/server/cache.d.ts +74 -0
  95. package/dist/server/cache.js +154 -0
  96. package/dist/server/emails.d.ts +142 -0
  97. package/dist/server/emails.js +123 -0
  98. package/dist/server/events.d.ts +357 -0
  99. package/dist/server/events.js +219 -0
  100. package/dist/server/functions.d.ts +40 -0
  101. package/dist/server/functions.js +1 -0
  102. package/dist/server/http-utils.d.ts +10 -0
  103. package/dist/server/http-utils.js +115 -0
  104. package/dist/server/index.d.ts +195 -0
  105. package/dist/server/index.js +314 -0
  106. package/dist/server/payments.d.ts +218 -0
  107. package/dist/server/payments.js +150 -0
  108. package/dist/server/push.d.ts +85 -0
  109. package/dist/server/push.js +37 -0
  110. package/dist/server/usage.d.ts +43 -0
  111. package/dist/server/usage.js +8 -0
  112. package/dist/storage/client.d.ts +143 -0
  113. package/dist/storage/client.js +224 -0
  114. package/package.json +52 -4
  115. package/skill/usebecky/SKILL.md +339 -0
  116. package/skill/usebecky/references/access-rules.md +307 -0
  117. package/skill/usebecky/references/addons.md +68 -0
  118. package/skill/usebecky/references/analytics.md +166 -0
  119. package/skill/usebecky/references/android.md +434 -0
  120. package/skill/usebecky/references/auth.md +379 -0
  121. package/skill/usebecky/references/cache.md +51 -0
  122. package/skill/usebecky/references/components.md +127 -0
  123. package/skill/usebecky/references/emails.md +105 -0
  124. package/skill/usebecky/references/expo.md +147 -0
  125. package/skill/usebecky/references/functions.md +99 -0
  126. package/skill/usebecky/references/hosting.md +119 -0
  127. package/skill/usebecky/references/http-api.md +233 -0
  128. package/skill/usebecky/references/ios.md +355 -0
  129. package/skill/usebecky/references/payments.md +493 -0
  130. package/skill/usebecky/references/realtime.md +143 -0
  131. package/skill/usebecky/references/scheduled-jobs.md +82 -0
  132. package/skill/usebecky/references/sdk.md +838 -0
  133. package/skill/usebecky/references/storage.md +210 -0
  134. package/skill/usebecky/references/templates.md +191 -0
  135. package/skill/usebecky/references/wordpress.md +87 -0
@@ -0,0 +1,219 @@
1
+ import type { HttpClient } from '../lib/http.ts';
2
+ import type { StorageAdapter } from '../lib/storage-adapter.ts';
3
+ import type { Result, Session } from '../lib/types.ts';
4
+ export interface AnalyticsOptions {
5
+ /** Collect events. Default true. `createClient(url, key, { analytics: false })` is the same as `{ enabled: false }`; call `baas.analytics.enable()` later (e.g. after cookie consent). */
6
+ enabled?: boolean;
7
+ /** Track a page view on load and on every client-side navigation (history.pushState / replaceState / popstate). Browser only. Default false. */
8
+ autoPageviews?: boolean;
9
+ /** Send nothing when the browser says Do Not Track (`navigator.doNotTrack === '1'`) or Global Privacy Control (`navigator.globalPrivacyControl`). Default true. */
10
+ respectDoNotTrack?: boolean;
11
+ /** Send queued events this often, in milliseconds. Default 5000. */
12
+ flushInterval?: number;
13
+ /** Send right away once this many events are queued. Default 20 (max 50). */
14
+ batchSize?: number;
15
+ /** Keep at most this many unsent events (e.g. while offline); the oldest are dropped. Default 500. */
16
+ maxQueueSize?: number;
17
+ /** A new session starts after this many minutes without events. Default 30 (local mode; in privacy mode the server uses 30). */
18
+ sessionTimeoutMinutes?: number;
19
+ /**
20
+ * `'none'`: privacy mode, the default in browsers. Nothing is stored on the device and no visitor or visit id
21
+ * is sent: the server recognizes a visitor for one day only (new vs returning isn't known).
22
+ * `'local'`: the default in React Native and Node. A random visitor id and the visit are kept in storage, so
23
+ * returning visitors are known across days. In a browser in the EU this usually needs consent first.
24
+ */
25
+ storage?: 'none' | 'local';
26
+ }
27
+ /**
28
+ * The current visit, sent with `payments.checkout()` and `payments.createPayment()` so the sale can be credited to the
29
+ * website or campaign that brought the buyer (Analytics → Traffic sources → Revenue by source). Nothing new is read
30
+ * from or written to the device for it.
31
+ */
32
+ export interface VisitRef {
33
+ /** A remembered device (after consent, or local mode): the random id its events already carry. */
34
+ anonymous_id?: string;
35
+ session_id?: string;
36
+ /** Privacy mode in a browser: only the page's hostname. The server recognizes the visitor from the request, the same
37
+ * way it does for events, and only links the visit that is still going on (the one the checkout came from). */
38
+ hostname?: string;
39
+ }
40
+ /**
41
+ * The visitor's consent state, sent with checkouts, payment forms, sign-ups and form submissions so a server-side
42
+ * tagging extension forwards the purchase, sign-up or lead with the right consent (and only when there is one).
43
+ */
44
+ export interface ConsentRef {
45
+ /** The visitor agreed to analytics (consent(true), or their cookie banner said yes). */
46
+ analytics: boolean;
47
+ /** With a yes, when the project asks for it: the Google Analytics client id from the _ga cookie ("123.456"). */
48
+ ga_client_id?: string;
49
+ }
50
+ export interface AnalyticsInit {
51
+ http: HttpClient;
52
+ key: string;
53
+ storage: StorageAdapter;
54
+ /** Prefix for storage keys, e.g. `ub-<ref>`. */
55
+ storageKey: string;
56
+ getSession: () => Session | null;
57
+ options?: boolean | AnalyticsOptions;
58
+ }
59
+ /** Limits enforced by the API (POST /analytics/v1/events). */
60
+ export declare const ANALYTICS_LIMITS: {
61
+ readonly maxBatch: 50;
62
+ readonly maxNameLength: 100;
63
+ readonly maxPropsBytes: 4096;
64
+ };
65
+ /** True when the browser asks not to be tracked: Do Not Track, or Global Privacy Control (like the website script). */
66
+ export declare function doNotTrack(): boolean;
67
+ export declare class AnalyticsClient {
68
+ private http;
69
+ private key;
70
+ private storage;
71
+ private keys;
72
+ private getSession;
73
+ private opts;
74
+ /** Privacy mode: no ids, nothing read from or written to storage except the opt-out and consent flags. */
75
+ private privacy;
76
+ /** `storage: 'none'` was set explicitly: consent() never switches to remembering. */
77
+ private alwaysPrivate;
78
+ /** The visitor agreed to be remembered and the project remembers visitors (consent()). */
79
+ private consented;
80
+ private disabledByConfig;
81
+ private optedOut;
82
+ /** The site owner's "Ignore my visits" flag in this browser (-analytics-ignore). */
83
+ private ignored;
84
+ /** Counts consent() calls: a config answer only applies to the latest one. */
85
+ private consentCalls;
86
+ /** The visitor's latest answer (consent(), the cookie banner, or a consent kept from an earlier page). */
87
+ private answer;
88
+ /** GET /analytics/v1/config, asked once per page load in a browser (null when it failed). */
89
+ private projectConfig;
90
+ /** Follows the site's cookie banner while the project says consent_source 'cmp' (cmp.ts). */
91
+ private banner;
92
+ /** The banner's answer last handed to consent() (only while collecting). */
93
+ private bannerApplied;
94
+ /** enable()/disable() was called, so the stored opt-out (loaded later from async storage) must not override it. */
95
+ private optOutDecided;
96
+ private queue;
97
+ private timer;
98
+ private retryDelay;
99
+ private flushing;
100
+ private anonId;
101
+ private session;
102
+ /** Date this device's anonymous id was first used ("YYYY-MM-DD"); null = no session yet (a new
103
+ * visitor); undefined = not loaded from (async) storage yet. */
104
+ private firstSeen;
105
+ /** UTM parameters in the address when this page loaded; used by the session the page starts. */
106
+ private landingUtm;
107
+ private context;
108
+ /** Ids created in memory but not yet written to storage: nothing is stored on the device until
109
+ * analytics is enabled and something is tracked (e.g. not before cookie consent). */
110
+ private unsaved;
111
+ /** Last access token seen per user, so events tracked before a sign-out still go out as that user. */
112
+ private tokens;
113
+ private lastPath;
114
+ private referrerSent;
115
+ private started;
116
+ private warned;
117
+ /** Resolves once the stored anonymous id / opt-out are loaded (async storage like AsyncStorage). */
118
+ private ready;
119
+ constructor(init: AnalyticsInit);
120
+ /** True when events are being collected (not disabled, not opted out, not the site owner's ignored browser, not blocked by Do Not Track or Global Privacy Control). */
121
+ get enabled(): boolean;
122
+ /**
123
+ * Record that something happened, e.g. `track('signed_up', { plan: 'pro' })`.
124
+ * `event`: up to 100 characters, not starting with "$". `props`: a JSON object up to 4 KB.
125
+ */
126
+ track(event: string, props?: Record<string, unknown>): void;
127
+ /**
128
+ * Record a page view (stored as the event `$pageview`). `path` defaults to `location.pathname`;
129
+ * the page title and, for the first page of a visit, the external referrer are sent too.
130
+ * Outside a browser, pass the path: `page('/pricing')`.
131
+ */
132
+ page(path?: string, props?: Record<string, unknown>): void;
133
+ /**
134
+ * Describe the current person, e.g. `identify({ plan: 'pro' })` after sign-in. The signed-in user
135
+ * id is attached automatically. Stored as the event `$identify` (not counted in event totals).
136
+ */
137
+ identify(traits?: Record<string, unknown>): void;
138
+ /** Send every queued event now. Await it before a Node script exits. Never throws.
139
+ * `sent` counts the events delivered by this call, including a send that was already in progress. */
140
+ flush(): Promise<Result<{
141
+ sent: number;
142
+ }>>;
143
+ /** Stop collecting and drop queued events. Remembered on this device (an opt-out) until enable(). */
144
+ disable(): void;
145
+ /** Start collecting again (also turns on a client created with `analytics: false`). Do Not Track still applies unless `respectDoNotTrack: false`. */
146
+ enable(): void;
147
+ /**
148
+ * The visitor's answer in your consent banner. `true`: when the project has "Remember returning visitors"
149
+ * on (Analytics → Settings), a random id is kept on this device so returning visitors are known across
150
+ * days (replaced after 13 months); otherwise nothing changes (privacy mode). `false`: the id is deleted
151
+ * and privacy mode is used again. The website script on the same site shares the choice.
152
+ */
153
+ consent(granted: boolean): void;
154
+ /**
155
+ * The visit to send along with a checkout or payment form (see `VisitRef`), or undefined: when the visitor opted out,
156
+ * Do Not Track applies, this is the site owner's ignored browser, or there is no visit to point at (a Node script, or
157
+ * a remembered id that was never used for an event). It doesn't depend on `enabled`: the website script may be the
158
+ * one counting visits while the SDK only handles sign-in and payments. Used by `baas.payments`; never throws.
159
+ */
160
+ visitRef(): VisitRef | undefined;
161
+ /**
162
+ * The visitor's consent state to send with a checkout, payment form, sign-up or form (see `ConsentRef`), or undefined
163
+ * when nobody answered. Global Privacy Control is always a no. With "Follow my cookie banner" on, the banner's answer
164
+ * comes first. Used by `baas.payments`, `baas.auth` and `baas.forms`; never throws.
165
+ */
166
+ consentRef(): Promise<ConsentRef | undefined>;
167
+ /** Forget this device's anonymous id and session (e.g. on a shared computer after sign-out). Privacy mode keeps nothing to forget. */
168
+ reset(): void;
169
+ private safely;
170
+ private warnOnce;
171
+ private read;
172
+ private write;
173
+ private remove;
174
+ /** GET /analytics/v1/config once per page load (null when it fails); `waitMs`: give up waiting after that long. */
175
+ private config;
176
+ /** Start following the site's cookie banner (once). Its answer goes to consent() while collecting; otherwise it
177
+ * is only remembered for consentRef(). */
178
+ private followBanner;
179
+ /** The banner answered: remember it; while collecting, hand it to consent() (once per change). */
180
+ private applyBanner;
181
+ /** Ask the project whether it remembers visitors; remember this device (`grant`) or forget it when it says it
182
+ * doesn't. `call`: the consent() call that asked; the answer is ignored once a later call was made. A failed
183
+ * request changes nothing. */
184
+ private checkConsent;
185
+ /** The site owner's "Ignore my visits" flag: #usebecky-ignore / #usebecky-count in the address set or clear it
186
+ * (like the website script), otherwise it is read from storage. */
187
+ private loadIgnored;
188
+ /** Switch from privacy mode to remembering this device (ids loaded from storage, or made). */
189
+ private rememberDevice;
190
+ /** Delete this device's ids and the consent, and use privacy mode from now on. */
191
+ private forgetDevice;
192
+ private load;
193
+ private parseSession;
194
+ /** Write ids that only lived in memory so far (called once analytics is on and in use). */
195
+ private persist;
196
+ /** Current session; starts a new one after `sessionTimeoutMinutes` of inactivity. */
197
+ private touchSession;
198
+ /** For the first event of a session: is this the device's first session? Undefined while async
199
+ * storage is still loading (decided at send time). */
200
+ private newVisitorFlag;
201
+ private currentSession;
202
+ private enqueue;
203
+ private push;
204
+ private schedule;
205
+ private clearTimer;
206
+ /** Up to `max` consecutive queued events tracked by the same user. */
207
+ private takeBatch;
208
+ /** Which access token goes with events tracked by `uid`: undefined = the current one (refreshed if needed), null = none. */
209
+ private tokenFor;
210
+ private withAnon;
211
+ private sendQueued;
212
+ /** Page is being hidden or closed: hand everything to sendBeacon (or fetch keepalive) synchronously. */
213
+ private flushOnExit;
214
+ /** text/plain + key in the URL = a "simple" request: no CORS preflight, allowed in sendBeacon. */
215
+ private beacon;
216
+ private externalReferrer;
217
+ /** Browser hooks: send on pagehide / tab hidden, and (opt-in) automatic page views. */
218
+ private start;
219
+ }