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,20 @@
1
+ /** true = the visitor agreed to analytics, false = they didn't (or GPC), undefined = no banner answered. */
2
+ export type ConsentAnswer = boolean | undefined;
3
+ /** TCF purposes analytics with a remembered visitor needs: 1 (store/access on a device) and 8 (measure content). */
4
+ export declare const TCF_PURPOSES: readonly [1, 8];
5
+ /** The latest Consent Mode answer for analytics_storage in a dataLayer (see 3. above). */
6
+ export declare function consentModeAnswer(dataLayer: unknown): ConsentAnswer;
7
+ /** A TCF v2.2 TCData → answer (see 4. above). */
8
+ export declare function tcfAnswer(tcData: any, success: boolean): ConsentAnswer;
9
+ export interface ConsentWatcher {
10
+ /** The answer right now. */
11
+ current(): ConsentAnswer;
12
+ stop(): void;
13
+ }
14
+ /**
15
+ * Follow the site's cookie banner: `onChange` is called with true / false whenever the answer changes (once right
16
+ * away when there already is one). Browser only; returns a watcher that answers undefined elsewhere.
17
+ */
18
+ export declare function watchConsentSignals(onChange: (granted: boolean) => void): ConsentWatcher;
19
+ /** The Google Analytics client id from the _ga cookie ("GA1.1.123.456" → "123.456"), or undefined. */
20
+ export declare function readGaClientId(): string | undefined;
@@ -0,0 +1,166 @@
1
+ // "Follow my cookie banner" (the project's analytics setting consent_source: 'cmp', from GET /analytics/v1/config):
2
+ // the visitor's answer in the site's cookie banner, read from the standard signals, in this order. Same rules as the
3
+ // website script (packages/server/src/modules/analytics/tracker/tracker.js), so both agree on one site.
4
+ //
5
+ // 1. Global Privacy Control (navigator.globalPrivacyControl): no.
6
+ // 2. cookiepass (window.Cookiepass): its "statistics" category (Cookiepass.hatEingewilligt('statistics'); no until
7
+ // the visitor decided). Followed live: the cmp_consent_updated and cookiepass:bereit events.
8
+ // 3. Google Consent Mode v2: analytics_storage from gtag('consent', 'update', …) in window.dataLayer (the latest
9
+ // update wins). A gtag('consent', 'default', …) is never an answer: it is the site's setting, and a banner that
10
+ // loads late sends its update after it (a default 'denied' must not make a returning visitor forget their id).
11
+ // Followed live by watching dataLayer.push (the site's own push still runs first).
12
+ // 4. IAB TCF v2.2 (window.__tcfapi): yes when purposes 1 ("Store and/or access information on a device") and 8
13
+ // ("Measure content performance") both have consent, as vendor purposes or as the publisher's own; no when
14
+ // not; nothing while the banner is still open or when the CMP says GDPR doesn't apply.
15
+ // None of them answers: undefined (nothing changes).
16
+ //
17
+ // Never throws into the page: a banner that behaves unexpectedly just doesn't answer.
18
+ const g = globalThis;
19
+ /** TCF purposes analytics with a remembered visitor needs: 1 (store/access on a device) and 8 (measure content). */
20
+ export const TCF_PURPOSES = [1, 8];
21
+ /** cookiepass's decision event and its "loaded" event (it also pushes to the dataLayer on every decision). */
22
+ const COOKIEPASS_EVENTS = ['cmp_consent_updated', 'cookiepass:bereit'];
23
+ /** The latest Consent Mode answer for analytics_storage in a dataLayer (see 3. above). */
24
+ export function consentModeAnswer(dataLayer) {
25
+ if (!Array.isArray(dataLayer))
26
+ return undefined;
27
+ let answer;
28
+ for (const e of dataLayer) {
29
+ if (!e || typeof e !== 'object' || e[0] !== 'consent' || e[1] !== 'update')
30
+ continue;
31
+ const v = e[2]?.analytics_storage;
32
+ if (v === 'granted' || v === 'denied')
33
+ answer = v === 'granted';
34
+ }
35
+ return answer;
36
+ }
37
+ /** A TCF v2.2 TCData → answer (see 4. above). */
38
+ export function tcfAnswer(tcData, success) {
39
+ if (!success || !tcData || tcData.gdprApplies !== true || tcData.eventStatus === 'cmpuishown')
40
+ return undefined;
41
+ return [tcData.purpose, tcData.publisher].some((o) => !!o?.consents && TCF_PURPOSES.every((p) => o.consents[p] === true));
42
+ }
43
+ /**
44
+ * Follow the site's cookie banner: `onChange` is called with true / false whenever the answer changes (once right
45
+ * away when there already is one). Browser only; returns a watcher that answers undefined elsewhere.
46
+ */
47
+ export function watchConsentSignals(onChange) {
48
+ const win = g.window;
49
+ if (!win || typeof win !== 'object')
50
+ return { current: () => undefined, stop() { } };
51
+ let tcf;
52
+ let last;
53
+ let stopped = false;
54
+ let cookiepassDetail;
55
+ const current = () => {
56
+ try {
57
+ if (g.navigator?.globalPrivacyControl === true)
58
+ return false;
59
+ const cp = win.Cookiepass;
60
+ if (cp && typeof cp.hatEingewilligt === 'function')
61
+ return !!cp.hatEingewilligt('statistics');
62
+ if (cookiepassDetail !== undefined)
63
+ return cookiepassDetail;
64
+ const cm = consentModeAnswer(win.dataLayer);
65
+ return cm !== undefined ? cm : tcf;
66
+ }
67
+ catch {
68
+ return undefined;
69
+ }
70
+ };
71
+ const check = () => {
72
+ if (stopped)
73
+ return;
74
+ const a = current();
75
+ if (a === undefined || a === last)
76
+ return;
77
+ last = a;
78
+ try {
79
+ onChange(a);
80
+ }
81
+ catch { }
82
+ };
83
+ const onCookiepass = (e) => {
84
+ // Without the JS API (an older or changed cookiepass), the event's own detail still says what was chosen.
85
+ const cats = e?.detail?.kategorien;
86
+ if (cats && typeof cats === 'object')
87
+ cookiepassDetail = !!cats.statistics;
88
+ check();
89
+ };
90
+ const undo = [];
91
+ try {
92
+ for (const type of COOKIEPASS_EVENTS) {
93
+ win.addEventListener?.(type, onCookiepass);
94
+ undo.push(() => win.removeEventListener?.(type, onCookiepass));
95
+ }
96
+ }
97
+ catch { }
98
+ // Consent Mode: watch pushes to the site's dataLayer (made here when the site has none yet, like gtag does; a
99
+ // dataLayer that isn't an array is the site's own business and left alone).
100
+ try {
101
+ if (win.dataLayer === undefined)
102
+ win.dataLayer = [];
103
+ const dl = win.dataLayer;
104
+ if (!Array.isArray(dl))
105
+ throw new Error('not an array');
106
+ const original = dl.push;
107
+ const watched = function (...args) {
108
+ const r = original.apply(dl, args);
109
+ try {
110
+ check();
111
+ }
112
+ catch { }
113
+ return r;
114
+ };
115
+ dl.push = watched;
116
+ undo.push(() => {
117
+ if (dl.push === watched)
118
+ dl.push = original;
119
+ });
120
+ }
121
+ catch { }
122
+ // TCF: the CMP calls back now with its current state and again after every change.
123
+ try {
124
+ if (typeof win.__tcfapi === 'function') {
125
+ let listenerId;
126
+ win.__tcfapi('addEventListener', 2, (tcData, success) => {
127
+ try {
128
+ if (tcData?.listenerId !== undefined)
129
+ listenerId = tcData.listenerId;
130
+ const a = tcfAnswer(tcData, success);
131
+ if (a !== undefined)
132
+ tcf = a;
133
+ check();
134
+ }
135
+ catch { }
136
+ });
137
+ undo.push(() => {
138
+ try {
139
+ if (listenerId !== undefined)
140
+ win.__tcfapi('removeEventListener', 2, () => { }, listenerId);
141
+ }
142
+ catch { }
143
+ });
144
+ }
145
+ }
146
+ catch { }
147
+ check();
148
+ return {
149
+ current,
150
+ stop() {
151
+ stopped = true;
152
+ for (const u of undo)
153
+ u();
154
+ },
155
+ };
156
+ }
157
+ /** The Google Analytics client id from the _ga cookie ("GA1.1.123.456" → "123.456"), or undefined. */
158
+ export function readGaClientId() {
159
+ try {
160
+ const m = /(?:^|;\s*)_ga=GA\d\.\d\.(\d{1,20}\.\d{1,20})(?:;|$)/.exec(String(g.document?.cookie ?? ''));
161
+ return m ? m[1] : undefined;
162
+ }
163
+ catch {
164
+ return undefined;
165
+ }
166
+ }
@@ -0,0 +1,29 @@
1
+ export declare const UTM_KEYS: readonly ["utm_source", "utm_medium", "utm_campaign", "utm_term", "utm_content"];
2
+ export type UtmKey = (typeof UTM_KEYS)[number];
3
+ /** Campaign parameters of a landing page, e.g. `{ utm_source: 'newsletter', utm_campaign: 'spring' }`. */
4
+ export type Utm = Partial<Record<UtmKey, string>>;
5
+ export type ScreenBucket = 'mobile' | 'tablet' | 'desktop' | 'large';
6
+ /** Device fields sent with every event (all optional). */
7
+ export interface VisitContext {
8
+ /** Primary language subtag, e.g. "en" (not "en-US"). */
9
+ language?: string;
10
+ /** IANA timezone, e.g. "Europe/Berlin". */
11
+ timezone?: string;
12
+ screen_size?: ScreenBucket;
13
+ }
14
+ /** Screen width in CSS pixels → bucket: mobile < 600, tablet < 1024, desktop < 1920, large ≥ 1920. */
15
+ export declare function screenBucket(width: unknown): ScreenBucket | undefined;
16
+ /** "en-US" → "en". */
17
+ export declare function primaryLanguage(tag: unknown): string | undefined;
18
+ /** UTM parameters from a query string ("?utm_source=x&utm_campaign=y&other=z"). `ref` or `source`
19
+ * fill in utm_source when it is missing. Every other parameter is ignored. */
20
+ export declare function utmFromSearch(search: unknown): Utm;
21
+ /** Only keeps known UTM keys with string values (for UTMs read back from storage). */
22
+ export declare function cleanUtm(v: unknown): Utm | undefined;
23
+ /** True where the device fields describe a real visitor (browser or React Native app). */
24
+ export declare function onVisitorDevice(inBrowser: boolean): boolean;
25
+ /** Language, timezone and screen bucket of this device. Empty outside a browser / React Native. */
26
+ export declare function visitContext(inBrowser: boolean): VisitContext;
27
+ /** Today's date (UTC) as "YYYY-MM-DD": the only thing stored about when a visitor was first seen. */
28
+ export declare function today(now?: number): string;
29
+ export declare const DATE: RegExp;
@@ -0,0 +1,97 @@
1
+ // Visit context the analytics client sends with each event: primary language, timezone, a screen
2
+ // size bucket (never the exact size) and the campaign (UTM) parameters of the landing page.
3
+ // Browser and React Native only: in Node these describe the server, not a visitor, so nothing is sent.
4
+ const g = globalThis;
5
+ export const UTM_KEYS = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content'];
6
+ const MAX_UTM_LENGTH = 200;
7
+ /** Screen width in CSS pixels → bucket: mobile < 600, tablet < 1024, desktop < 1920, large ≥ 1920. */
8
+ export function screenBucket(width) {
9
+ if (typeof width !== 'number' || !Number.isFinite(width) || width <= 0)
10
+ return undefined;
11
+ if (width < 600)
12
+ return 'mobile';
13
+ if (width < 1024)
14
+ return 'tablet';
15
+ if (width < 1920)
16
+ return 'desktop';
17
+ return 'large';
18
+ }
19
+ /** "en-US" → "en". */
20
+ export function primaryLanguage(tag) {
21
+ if (typeof tag !== 'string')
22
+ return undefined;
23
+ const sub = tag.trim().split(/[-_]/)[0].toLowerCase();
24
+ return /^[a-z]{2,3}$/.test(sub) ? sub : undefined;
25
+ }
26
+ /** UTM parameters from a query string ("?utm_source=x&utm_campaign=y&other=z"). `ref` or `source`
27
+ * fill in utm_source when it is missing. Every other parameter is ignored. */
28
+ export function utmFromSearch(search) {
29
+ if (typeof search !== 'string' || !search.includes('='))
30
+ return {};
31
+ let params;
32
+ try {
33
+ params = new URLSearchParams(search.startsWith('?') ? search.slice(1) : search);
34
+ }
35
+ catch {
36
+ return {};
37
+ }
38
+ const out = {};
39
+ const take = (key) => params.get(key)?.trim().slice(0, MAX_UTM_LENGTH) || undefined;
40
+ for (const k of UTM_KEYS) {
41
+ const v = take(k);
42
+ if (v)
43
+ out[k] = v;
44
+ }
45
+ if (!out.utm_source) {
46
+ const fallback = take('ref') ?? take('source');
47
+ if (fallback)
48
+ out.utm_source = fallback;
49
+ }
50
+ return out;
51
+ }
52
+ /** Only keeps known UTM keys with string values (for UTMs read back from storage). */
53
+ export function cleanUtm(v) {
54
+ if (!v || typeof v !== 'object')
55
+ return undefined;
56
+ const out = {};
57
+ for (const k of UTM_KEYS) {
58
+ const s = v[k];
59
+ if (typeof s === 'string' && s)
60
+ out[k] = s.slice(0, MAX_UTM_LENGTH);
61
+ }
62
+ return Object.keys(out).length ? out : undefined;
63
+ }
64
+ function isReactNative() {
65
+ return g.navigator?.product === 'ReactNative';
66
+ }
67
+ /** True where the device fields describe a real visitor (browser or React Native app). */
68
+ export function onVisitorDevice(inBrowser) {
69
+ return inBrowser || isReactNative();
70
+ }
71
+ /** Language, timezone and screen bucket of this device. Empty outside a browser / React Native. */
72
+ export function visitContext(inBrowser) {
73
+ if (!onVisitorDevice(inBrowser))
74
+ return {};
75
+ const ctx = {};
76
+ let locale;
77
+ try {
78
+ const opts = Intl.DateTimeFormat().resolvedOptions();
79
+ if (typeof opts.timeZone === 'string' && opts.timeZone)
80
+ ctx.timezone = opts.timeZone;
81
+ locale = opts.locale;
82
+ }
83
+ catch { }
84
+ const nav = g.navigator;
85
+ const language = primaryLanguage(nav?.language ?? nav?.languages?.[0] ?? locale);
86
+ if (language)
87
+ ctx.language = language;
88
+ const screen = screenBucket(g.screen?.width);
89
+ if (screen)
90
+ ctx.screen_size = screen;
91
+ return ctx;
92
+ }
93
+ /** Today's date (UTC) as "YYYY-MM-DD": the only thing stored about when a visitor was first seen. */
94
+ export function today(now = Date.now()) {
95
+ return new Date(now).toISOString().slice(0, 10);
96
+ }
97
+ export const DATE = /^\d{4}-\d{2}-\d{2}$/;