@tappify/extension-sdk 2.0.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.
- package/LICENSE +21 -0
- package/dist/chunk-2DBSVKAU.cjs +65 -0
- package/dist/chunk-2DBSVKAU.cjs.map +1 -0
- package/dist/chunk-3YWVYA42.cjs +142 -0
- package/dist/chunk-3YWVYA42.cjs.map +1 -0
- package/dist/chunk-4C5Z3CIK.mjs +26 -0
- package/dist/chunk-4C5Z3CIK.mjs.map +1 -0
- package/dist/chunk-5AAPD5WV.cjs +250 -0
- package/dist/chunk-5AAPD5WV.cjs.map +1 -0
- package/dist/chunk-7KIKOH5H.cjs +26 -0
- package/dist/chunk-7KIKOH5H.cjs.map +1 -0
- package/dist/chunk-BDCX6LRQ.mjs +250 -0
- package/dist/chunk-BDCX6LRQ.mjs.map +1 -0
- package/dist/chunk-CSTYBKZC.mjs +65 -0
- package/dist/chunk-CSTYBKZC.mjs.map +1 -0
- package/dist/chunk-IGK2AP6J.mjs +142 -0
- package/dist/chunk-IGK2AP6J.mjs.map +1 -0
- package/dist/chunk-MNDVYPEP.mjs +302 -0
- package/dist/chunk-MNDVYPEP.mjs.map +1 -0
- package/dist/chunk-OPPYEA7F.cjs +33 -0
- package/dist/chunk-OPPYEA7F.cjs.map +1 -0
- package/dist/chunk-PYJMJF44.cjs +302 -0
- package/dist/chunk-PYJMJF44.cjs.map +1 -0
- package/dist/chunk-QHM7XNRK.mjs +33 -0
- package/dist/chunk-QHM7XNRK.mjs.map +1 -0
- package/dist/chunk-RMUWRESK.cjs +365 -0
- package/dist/chunk-RMUWRESK.cjs.map +1 -0
- package/dist/chunk-ZT35X7KL.mjs +365 -0
- package/dist/chunk-ZT35X7KL.mjs.map +1 -0
- package/dist/codegen.cjs +300 -0
- package/dist/codegen.cjs.map +1 -0
- package/dist/codegen.d.cts +432 -0
- package/dist/codegen.d.ts +432 -0
- package/dist/codegen.mjs +272 -0
- package/dist/codegen.mjs.map +1 -0
- package/dist/constants-DJ_KgZpN.d.cts +449 -0
- package/dist/constants-DJ_KgZpN.d.ts +449 -0
- package/dist/context-Dt6xh_5t.d.cts +30 -0
- package/dist/context-Ml7k_V14.d.ts +30 -0
- package/dist/errors-COsBh7kd.d.cts +88 -0
- package/dist/errors-COsBh7kd.d.ts +88 -0
- package/dist/handler-CZIlZ5vu.d.ts +227 -0
- package/dist/handler-kU9Jf36K.d.cts +227 -0
- package/dist/host.cjs +24 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.d.cts +24 -0
- package/dist/host.d.ts +24 -0
- package/dist/host.mjs +24 -0
- package/dist/host.mjs.map +1 -0
- package/dist/index.cjs +698 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1016 -0
- package/dist/index.d.ts +1016 -0
- package/dist/index.mjs +698 -0
- package/dist/index.mjs.map +1 -0
- package/dist/manifest.cjs +872 -0
- package/dist/manifest.cjs.map +1 -0
- package/dist/manifest.d.cts +432 -0
- package/dist/manifest.d.ts +432 -0
- package/dist/manifest.mjs +872 -0
- package/dist/manifest.mjs.map +1 -0
- package/dist/matchers-Cz93AK1n.d.cts +74 -0
- package/dist/matchers-Cz93AK1n.d.ts +74 -0
- package/dist/server.cjs +210 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +243 -0
- package/dist/server.d.ts +243 -0
- package/dist/server.mjs +210 -0
- package/dist/server.mjs.map +1 -0
- package/dist/styles.css +367 -0
- package/dist/testing/index.cjs +887 -0
- package/dist/testing/index.cjs.map +1 -0
- package/dist/testing/index.d.cts +512 -0
- package/dist/testing/index.d.ts +512 -0
- package/dist/testing/index.mjs +887 -0
- package/dist/testing/index.mjs.map +1 -0
- package/dist/testing/jest.cjs +17 -0
- package/dist/testing/jest.cjs.map +1 -0
- package/dist/testing/jest.d.cts +12 -0
- package/dist/testing/jest.d.ts +12 -0
- package/dist/testing/jest.mjs +17 -0
- package/dist/testing/jest.mjs.map +1 -0
- package/dist/testing/vitest.cjs +15 -0
- package/dist/testing/vitest.cjs.map +1 -0
- package/dist/testing/vitest.d.cts +10 -0
- package/dist/testing/vitest.d.ts +10 -0
- package/dist/testing/vitest.mjs +15 -0
- package/dist/testing/vitest.mjs.map +1 -0
- package/dist/types-DDAGLpov.d.ts +715 -0
- package/dist/types-DrpQSv_2.d.cts +715 -0
- package/dist/vite.cjs +1344 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.d.cts +434 -0
- package/dist/vite.d.ts +434 -0
- package/dist/vite.mjs +1314 -0
- package/dist/vite.mjs.map +1 -0
- package/package.json +268 -0
- package/schema/extension-v2.json +1500 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tappify Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/client/errors.ts
|
|
2
|
+
var TAP_ERROR_CODES = [
|
|
3
|
+
"TAP_OUTSIDE_HOST",
|
|
4
|
+
"TAP_SCOPE_MISSING",
|
|
5
|
+
"TAP_UNKNOWN_COLLECTION",
|
|
6
|
+
"TAP_UNKNOWN_PROCEDURE",
|
|
7
|
+
"TAP_NO_PORTAL",
|
|
8
|
+
"TAP_NO_QUERY_CLIENT",
|
|
9
|
+
"TAP_MANIFEST_INVALID",
|
|
10
|
+
"TAP_ENTRY_MISSING",
|
|
11
|
+
"TAP_STYLES_UNRESOLVED",
|
|
12
|
+
"TAP_SCHEMA_UNRESOLVED",
|
|
13
|
+
"TAP_TOKEN_MISSING",
|
|
14
|
+
"TAP_TOKEN_INVALID",
|
|
15
|
+
"TAP_TOKEN_AUDIENCE",
|
|
16
|
+
"TAP_EVENT_ID_MISSING",
|
|
17
|
+
"TAP_BODY_INVALID",
|
|
18
|
+
"TAP_BODY_TOO_LARGE",
|
|
19
|
+
"TAP_ROUTE_UNKNOWN",
|
|
20
|
+
"TAP_HANDLER_MISSING",
|
|
21
|
+
"TAP_INTERNAL_ERROR",
|
|
22
|
+
"TAP_WEBHOOK_REJECTED",
|
|
23
|
+
"TAP_TEST_TARGET_INVALID"
|
|
24
|
+
];
|
|
25
|
+
var CODE_SET = new Set(TAP_ERROR_CODES);
|
|
26
|
+
var TapError = class extends Error {
|
|
27
|
+
constructor(code, message) {
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = "TapError";
|
|
30
|
+
this.code = code;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Narrows an unknown value to a `TapError`, by name and by a code it
|
|
34
|
+
* recognises, so it holds across module instances.
|
|
35
|
+
*/
|
|
36
|
+
static is(value) {
|
|
37
|
+
return value instanceof Error && value.name === "TapError" && "code" in value && typeof value.code === "string" && CODE_SET.has(value.code);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var TapServerError = class extends Error {
|
|
41
|
+
constructor(code, message, status) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = "TapServerError";
|
|
44
|
+
this.code = code;
|
|
45
|
+
this.status = status;
|
|
46
|
+
}
|
|
47
|
+
/** The wire body the handler answers with, without the status. */
|
|
48
|
+
toJSON() {
|
|
49
|
+
return { error: { code: this.code, message: this.message } };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Narrows an unknown value to a `TapServerError` by name and by carrying a
|
|
53
|
+
* string `code`, so it holds across module instances.
|
|
54
|
+
*/
|
|
55
|
+
static is(value) {
|
|
56
|
+
return value instanceof Error && value.name === "TapServerError" && "code" in value && typeof value.code === "string";
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
exports.TAP_ERROR_CODES = TAP_ERROR_CODES; exports.TapError = TapError; exports.TapServerError = TapServerError;
|
|
65
|
+
//# sourceMappingURL=chunk-2DBSVKAU.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/vulakh/Desktop/Work/Tappify/extension-sdk/dist/chunk-2DBSVKAU.cjs","../src/client/errors.ts"],"names":[],"mappings":"AAAA;AC4BO,IAAM,gBAAA,EAA2C;AAAA,EACtD,kBAAA;AAAA,EACA,mBAAA;AAAA,EACA,wBAAA;AAAA,EACA,uBAAA;AAAA,EACA,eAAA;AAAA,EACA,qBAAA;AAAA,EACA,sBAAA;AAAA,EACA,mBAAA;AAAA,EACA,uBAAA;AAAA,EACA,uBAAA;AAAA,EACA,mBAAA;AAAA,EACA,mBAAA;AAAA,EACA,oBAAA;AAAA,EACA,sBAAA;AAAA,EACA,kBAAA;AAAA,EACA,oBAAA;AAAA,EACA,mBAAA;AAAA,EACA,q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AAA,GAAU,MAAA,GACV,OAAO,KAAA,CAAM,KAAA,IAAS,QAAA;AAAA,EAE1B;AACF,CAAA;ADrGA;AACA;AACE;AACA;AACA;AACF,gHAAC","file":"/Users/vulakh/Desktop/Work/Tappify/extension-sdk/dist/chunk-2DBSVKAU.cjs","sourcesContent":[null,"/** Every code a `TapError` the SDK raises carries. */\nexport type TapErrorCode =\n | 'TAP_OUTSIDE_HOST'\n | 'TAP_SCOPE_MISSING'\n | 'TAP_UNKNOWN_COLLECTION'\n | 'TAP_UNKNOWN_PROCEDURE'\n | 'TAP_NO_PORTAL'\n | 'TAP_NO_QUERY_CLIENT'\n | 'TAP_MANIFEST_INVALID'\n | 'TAP_ENTRY_MISSING'\n | 'TAP_STYLES_UNRESOLVED'\n | 'TAP_SCHEMA_UNRESOLVED'\n | 'TAP_TOKEN_MISSING'\n | 'TAP_TOKEN_INVALID'\n | 'TAP_TOKEN_AUDIENCE'\n | 'TAP_EVENT_ID_MISSING'\n | 'TAP_BODY_INVALID'\n | 'TAP_BODY_TOO_LARGE'\n | 'TAP_ROUTE_UNKNOWN'\n | 'TAP_HANDLER_MISSING'\n | 'TAP_INTERNAL_ERROR'\n | 'TAP_WEBHOOK_REJECTED'\n | 'TAP_TEST_TARGET_INVALID';\n\n/**\n * The same codes as `TapErrorCode`, as an array to iterate or check membership\n * against at runtime.\n */\nexport const TAP_ERROR_CODES: readonly TapErrorCode[] = [\n 'TAP_OUTSIDE_HOST',\n 'TAP_SCOPE_MISSING',\n 'TAP_UNKNOWN_COLLECTION',\n 'TAP_UNKNOWN_PROCEDURE',\n 'TAP_NO_PORTAL',\n 'TAP_NO_QUERY_CLIENT',\n 'TAP_MANIFEST_INVALID',\n 'TAP_ENTRY_MISSING',\n 'TAP_STYLES_UNRESOLVED',\n 'TAP_SCHEMA_UNRESOLVED',\n 'TAP_TOKEN_MISSING',\n 'TAP_TOKEN_INVALID',\n 'TAP_TOKEN_AUDIENCE',\n 'TAP_EVENT_ID_MISSING',\n 'TAP_BODY_INVALID',\n 'TAP_BODY_TOO_LARGE',\n 'TAP_ROUTE_UNKNOWN',\n 'TAP_HANDLER_MISSING',\n 'TAP_INTERNAL_ERROR',\n 'TAP_WEBHOOK_REJECTED',\n 'TAP_TEST_TARGET_INVALID',\n];\n\nconst CODE_SET = new Set<string>(TAP_ERROR_CODES);\n\n/**\n * The error the SDK and the host raise when a call cannot be served at all.\n *\n * @remarks\n * The SDK throws it for a mount outside the host (`TAP_OUTSIDE_HOST`), a\n * collection or procedure the manifest does not declare\n * (`TAP_UNKNOWN_COLLECTION`, `TAP_UNKNOWN_PROCEDURE`), a missing portal or query\n * client, a token the server rejected, and a misused testing helper. The host\n * turns a refused read or write into `TAP_SCOPE_MISSING`. Branch on `code`, which\n * is stable; the message is prose and changes. An error your own server raised is\n * a `TapServerError` instead.\n *\n * @example\n * ```tsx\n * import { TapError, TapErrorState, useTapQuery } from '@tappify/extension-sdk';\n *\n * function Revenue() {\n * const revenue = useTapQuery({\n * kind: 'revenue',\n * range: { from: '2026-09-01', to: '2026-09-08' },\n * });\n * if (TapError.is(revenue.error) && revenue.error.code === 'TAP_SCOPE_MISSING') {\n * return <TapErrorState title=\"Revenue is not shared with this extension\" />;\n * }\n * return <span>{revenue.data?.mrr ?? 0}</span>;\n * }\n * ```\n */\nexport class TapError extends Error {\n readonly code: TapErrorCode;\n\n constructor(code: TapErrorCode, message: string) {\n super(message);\n this.name = 'TapError';\n this.code = code;\n }\n\n /**\n * Narrows an unknown value to a `TapError`, by name and by a code it\n * recognises, so it holds across module instances.\n */\n static is(value: unknown): value is TapError {\n return (\n value instanceof Error &&\n value.name === 'TapError' &&\n 'code' in value &&\n typeof value.code === 'string' &&\n CODE_SET.has(value.code)\n );\n }\n}\n\n/**\n * The error a vendor server throws to answer a Tappify call with a code and a\n * message the owner sees.\n *\n * @remarks\n * `createTappifyHandler` catches it and answers `{ error: { code, message } }`\n * with `status`, or 400 when no status was given; the host relays both to the\n * calling mount, where they arrive as the `error` of `useTapServer`. Pick a code\n * of your own and keep it stable — the SDK's own codes are `SERVER_ERROR_CODES` —\n * and write the message for the owner, who reads it on screen.\n *\n * @example\n * ```ts\n * import { TapServerError } from '@tappify/extension-sdk/server';\n *\n * function assertRange(days: number) {\n * if (days > 0) return;\n * throw new TapServerError(\n * 'RANGE_TOO_SHORT',\n * 'getSummary needs a range of at least one day. Widen the date picker, then retry.',\n * 400,\n * );\n * }\n * ```\n */\nexport class TapServerError extends Error {\n readonly code: string;\n readonly status: number | undefined;\n\n constructor(code: string, message: string, status?: number) {\n super(message);\n this.name = 'TapServerError';\n this.code = code;\n this.status = status;\n }\n\n /** The wire body the handler answers with, without the status. */\n toJSON(): { error: { code: string; message: string } } {\n return { error: { code: this.code, message: this.message } };\n }\n\n /**\n * Narrows an unknown value to a `TapServerError` by name and by carrying a\n * string `code`, so it holds across module instances.\n */\n static is(value: unknown): value is TapServerError {\n return (\n value instanceof Error &&\n value.name === 'TapServerError' &&\n 'code' in value &&\n typeof value.code === 'string'\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk2DBSVKAUcjs = require('./chunk-2DBSVKAU.cjs');
|
|
4
|
+
|
|
5
|
+
// src/testing/environment.ts
|
|
6
|
+
var HOST_THEME = {
|
|
7
|
+
"--bg-base": "#ffffff",
|
|
8
|
+
"--bg-subtle": "rgba(18, 18, 18, 0.04)",
|
|
9
|
+
"--bg-raised": "#ffffff",
|
|
10
|
+
"--fg-default": "#121212",
|
|
11
|
+
"--fg-muted": "rgba(18, 18, 18, 0.6)",
|
|
12
|
+
"--fg-inverse": "#ffffff",
|
|
13
|
+
"--tap-accent": "#4f46e5",
|
|
14
|
+
"--tap-accent-fg": "#ffffff",
|
|
15
|
+
"--tap-danger": "#b42318",
|
|
16
|
+
"--tap-scrim": "rgba(18, 18, 18, 0.7)",
|
|
17
|
+
"--tap-radius": "6px",
|
|
18
|
+
"--tap-space": "8px",
|
|
19
|
+
"--font-sans": "system-ui, -apple-system, sans-serif",
|
|
20
|
+
"--font-mono": "ui-monospace, SFMono-Regular, monospace",
|
|
21
|
+
"--divider": "rgba(18, 18, 18, 0.12)"
|
|
22
|
+
};
|
|
23
|
+
function installHostTheme(root) {
|
|
24
|
+
for (const [name, value] of Object.entries(HOST_THEME)) {
|
|
25
|
+
root.style.setProperty(name, value);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function clearTapPortals(root = document) {
|
|
29
|
+
for (const node of root.querySelectorAll("[data-tap-portal]")) node.remove();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/testing/matchers.ts
|
|
33
|
+
function isMock(value) {
|
|
34
|
+
return typeof value === "object" && value !== null && "calls" in value && "documents" in value && typeof value.documents === "function";
|
|
35
|
+
}
|
|
36
|
+
function requireMock(value, matcher) {
|
|
37
|
+
if (isMock(value)) return value;
|
|
38
|
+
throw new (0, _chunk2DBSVKAUcjs.TapError)(
|
|
39
|
+
"TAP_TEST_TARGET_INVALID",
|
|
40
|
+
`${matcher}() takes the mock renderWithTap() returned. Call it as expect(mock).${matcher}(\u2026), not on the component or the tap object.`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function tagOf(value) {
|
|
44
|
+
return Object.prototype.toString.call(value);
|
|
45
|
+
}
|
|
46
|
+
function sameList(left, right) {
|
|
47
|
+
return left.length === right.length && left.every((item, index) => same(item, right[index]));
|
|
48
|
+
}
|
|
49
|
+
function bytesOf(view) {
|
|
50
|
+
return [...new Uint8Array(view.buffer, view.byteOffset, view.byteLength)];
|
|
51
|
+
}
|
|
52
|
+
function same(left, right) {
|
|
53
|
+
if (Object.is(left, right)) return true;
|
|
54
|
+
const tag = tagOf(left);
|
|
55
|
+
if (tag !== tagOf(right)) return false;
|
|
56
|
+
if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
if (left instanceof Date && right instanceof Date) {
|
|
60
|
+
return left.valueOf() === right.valueOf();
|
|
61
|
+
}
|
|
62
|
+
if (left instanceof RegExp && right instanceof RegExp) {
|
|
63
|
+
return left.source === right.source && left.flags === right.flags;
|
|
64
|
+
}
|
|
65
|
+
if (left instanceof Map && right instanceof Map) {
|
|
66
|
+
return sameList([...left.entries()], [...right.entries()]);
|
|
67
|
+
}
|
|
68
|
+
if (left instanceof Set && right instanceof Set) {
|
|
69
|
+
return sameList([...left.values()], [...right.values()]);
|
|
70
|
+
}
|
|
71
|
+
if (ArrayBuffer.isView(left) && ArrayBuffer.isView(right)) {
|
|
72
|
+
return sameList(bytesOf(left), bytesOf(right));
|
|
73
|
+
}
|
|
74
|
+
if (Array.isArray(left) && Array.isArray(right)) {
|
|
75
|
+
return sameList(left, right);
|
|
76
|
+
}
|
|
77
|
+
if (tag !== "[object Object]") return false;
|
|
78
|
+
const keys = Object.keys(left);
|
|
79
|
+
return keys.length === Object.keys(right).length && keys.every(
|
|
80
|
+
(key) => key in right && same(Reflect.get(left, key), Reflect.get(right, key))
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
var tapMatchers = {
|
|
84
|
+
/** Passes when `tap.nav.push` was called with exactly that path. */
|
|
85
|
+
toHaveNavigatedTo(received, path) {
|
|
86
|
+
const mock = requireMock(received, "toHaveNavigatedTo");
|
|
87
|
+
const pass = mock.calls.navigations.includes(path);
|
|
88
|
+
return {
|
|
89
|
+
pass,
|
|
90
|
+
message: () => pass ? `Expected no navigation to ${path}, but tap.nav.push was called with it.` : `Expected a navigation to ${path}. tap.nav.push was called with: ${mock.calls.navigations.length === 0 ? "nothing" : mock.calls.navigations.join(", ")}.`
|
|
91
|
+
};
|
|
92
|
+
},
|
|
93
|
+
/** Passes when a toast matched the string exactly, or the pattern anywhere. */
|
|
94
|
+
toHaveToasted(received, expected) {
|
|
95
|
+
const mock = requireMock(received, "toHaveToasted");
|
|
96
|
+
const messages = mock.calls.toasts.map((toast) => toast.message);
|
|
97
|
+
const pass = messages.some(
|
|
98
|
+
(message) => typeof expected === "string" ? message === expected : expected.test(message)
|
|
99
|
+
);
|
|
100
|
+
return {
|
|
101
|
+
pass,
|
|
102
|
+
message: () => pass ? `Expected no toast matching ${String(expected)}, but one was shown.` : `Expected a toast matching ${String(expected)}. Toasts shown: ${messages.length === 0 ? "none" : messages.join(" | ")}.`
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
/**
|
|
106
|
+
* Passes when `tap.actions.run` was called with that action, and with input
|
|
107
|
+
* deep-equal to `input` when one is given.
|
|
108
|
+
*/
|
|
109
|
+
toHaveRunAction(received, actionId, input) {
|
|
110
|
+
const mock = requireMock(received, "toHaveRunAction");
|
|
111
|
+
const runs = mock.calls.actions.filter((run) => run.actionId === actionId);
|
|
112
|
+
const pass = input === void 0 ? runs.length > 0 : runs.some((run) => same(run.input, input));
|
|
113
|
+
return {
|
|
114
|
+
pass,
|
|
115
|
+
message: () => pass ? `Expected tap.actions.run("${actionId}") not to be called.` : `Expected tap.actions.run("${actionId}"${input === void 0 ? "" : `, ${JSON.stringify(input)}`}). Runs recorded: ${mock.calls.actions.length === 0 ? "none" : JSON.stringify(mock.calls.actions)}.`
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
/**
|
|
119
|
+
* Passes when the mock's storage holds a document deep-equal to that one in
|
|
120
|
+
* that collection.
|
|
121
|
+
*/
|
|
122
|
+
toHaveStored(received, collection, document2) {
|
|
123
|
+
const mock = requireMock(received, "toHaveStored");
|
|
124
|
+
const stored = mock.documents(collection);
|
|
125
|
+
const pass = stored.some((candidate) => same(candidate, document2));
|
|
126
|
+
return {
|
|
127
|
+
pass,
|
|
128
|
+
message: () => pass ? `Expected "${collection}" not to hold ${JSON.stringify(document2)}.` : `Expected "${collection}" to hold ${JSON.stringify(document2)}. It holds: ${stored.length === 0 ? "nothing" : JSON.stringify(stored)}.`
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
function registerTapMatchers(target) {
|
|
133
|
+
target.extend(tapMatchers);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
exports.installHostTheme = installHostTheme; exports.clearTapPortals = clearTapPortals; exports.tapMatchers = tapMatchers; exports.registerTapMatchers = registerTapMatchers;
|
|
142
|
+
//# sourceMappingURL=chunk-3YWVYA42.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/vulakh/Desktop/Work/Tappify/extension-sdk/dist/chunk-3YWVYA42.cjs","../src/testing/environment.ts","../src/testing/matchers.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,IAAM,WAAA,EAAqC;AAAA,EACzC,WAAA,EAAa,SAAA;AAAA,EACb,aAAA,EAAe,wBAAA;AAAA,EACf,aAAA,EAAe,SAAA;AAAA,EACf,cAAA,EAAgB,SAAA;AAAA,EAChB,YAAA,EAAc,uBAAA;AAAA,EACd,cAAA,EAAgB,SAAA;AAAA,EAChB,cAAA,EAAgB,SAAA;AAAA,EAChB,iBAAA,EAAmB,SAAA;AAAA,EACnB,cAAA,EAAgB,SAAA;AAAA,EAChB,aAAA,EAAe,uBAAA;AAAA,EACf,cAAA,EAAgB,KAAA;AAAA,EAChB,aAAA,EAAe,KAAA;AAAA,EACf,aAAA,EAAe,sCAAA;AAAA,EACf,aAAA,EAAe,yCAAA;AAAA,EACf,WAAA,EAAa;AACf,CAAA;AA0BO,SAAS,gBAAA,CAAiB,IAAA,EAAyB;AACxD,EAAA,IAAA,CAAA,MAAW,CAAC,IAAA,EAAM,KAAK,EAAA,GAAK,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,EAAG;AACtD,IAAA,IAAA,CAAK,KAAA,CAAM,WAAA,CAAY,IAAA,EAAM,KAAK,CAAA;AAAA,EACpC;AACF;AAEO,SAAS,eAAA,CA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AA;AAMA,EAAA;AAKE,IAAA;AACA,IAAA;AACA,IAAA;AAIA,IAAA;AAAO,MAAA;AACL,MAAA;AAWF,IAAA;AACF,EAAA;AAAA;AAAA;AAAA;AAAA;AAMA,EAAA;AAKE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAO,MAAA;AACL,MAAA;AAOF,IAAA;AACF,EAAA;AACF;AAqBO;AACL,EAAA;AACF;AFlGK;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/vulakh/Desktop/Work/Tappify/extension-sdk/dist/chunk-3YWVYA42.cjs","sourcesContent":[null,"const HOST_THEME: Record<string, string> = {\n '--bg-base': '#ffffff',\n '--bg-subtle': 'rgba(18, 18, 18, 0.04)',\n '--bg-raised': '#ffffff',\n '--fg-default': '#121212',\n '--fg-muted': 'rgba(18, 18, 18, 0.6)',\n '--fg-inverse': '#ffffff',\n '--tap-accent': '#4f46e5',\n '--tap-accent-fg': '#ffffff',\n '--tap-danger': '#b42318',\n '--tap-scrim': 'rgba(18, 18, 18, 0.7)',\n '--tap-radius': '6px',\n '--tap-space': '8px',\n '--font-sans': 'system-ui, -apple-system, sans-serif',\n '--font-mono': 'ui-monospace, SFMono-Regular, monospace',\n '--divider': 'rgba(18, 18, 18, 0.12)',\n};\n\n/**\n * Sets the host's fifteen CSS variables on an element, so a component renders in\n * a test the way it renders in the host.\n *\n * @remarks\n * Sets the light values as inline custom properties, which inherit into everything\n * below the element. The vitest and jest presets call it on\n * `document.documentElement` for you, so call it yourself only in a test that\n * renders outside `renderWithTap` or wants the variables on one subtree. It sets\n * no dark values; drive the mode through `renderWithTap`'s `theme` option, which\n * is what `useTapTheme` reads.\n *\n * @example\n * ```ts\n * import { installHostTheme } from '@tappify/extension-sdk/testing';\n *\n * function mountRoot(): HTMLElement {\n * const root = document.createElement('div');\n * installHostTheme(root);\n * document.body.append(root);\n * return root;\n * }\n * ```\n */\nexport function installHostTheme(root: HTMLElement): void {\n for (const [name, value] of Object.entries(HOST_THEME)) {\n root.style.setProperty(name, value);\n }\n}\n\nexport function clearTapPortals(root: ParentNode = document): void {\n for (const node of root.querySelectorAll('[data-tap-portal]')) node.remove();\n}\n","import { TapError } from '../client/errors';\nimport type { TapMock } from './mock';\n\n/** What each matcher returns, in the shape vitest and jest both read. */\nexport interface MatcherResult {\n pass: boolean;\n /** Built only when the runner reports, and worded for both `expect` and `not`. */\n message(): string;\n}\n\n/** The part of a runner's `expect` that `registerTapMatchers` needs. */\nexport interface MatcherTarget {\n /** Both runners take a map of matcher functions keyed by matcher name. */\n extend(matchers: Record<string, unknown>): void;\n}\n\nfunction isMock(value: unknown): value is TapMock {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'calls' in value &&\n 'documents' in value &&\n typeof value.documents === 'function'\n );\n}\n\nfunction requireMock(value: unknown, matcher: string): TapMock {\n if (isMock(value)) return value;\n throw new TapError(\n 'TAP_TEST_TARGET_INVALID',\n `${matcher}() takes the mock renderWithTap() returned. Call it as expect(mock).${matcher}(…), not on the component or the tap object.`,\n );\n}\n\nfunction tagOf(value: unknown): string {\n return Object.prototype.toString.call(value);\n}\n\nfunction sameList(left: unknown[], right: unknown[]): boolean {\n return (\n left.length === right.length &&\n left.every((item, index) => same(item, right[index]))\n );\n}\n\nfunction bytesOf(view: ArrayBufferView): number[] {\n return [...new Uint8Array(view.buffer, view.byteOffset, view.byteLength)];\n}\n\nfunction same(left: unknown, right: unknown): boolean {\n if (Object.is(left, right)) return true;\n\n const tag = tagOf(left);\n if (tag !== tagOf(right)) return false;\n\n if (\n typeof left !== 'object' ||\n typeof right !== 'object' ||\n left === null ||\n right === null\n ) {\n return false;\n }\n\n if (left instanceof Date && right instanceof Date) {\n return left.valueOf() === right.valueOf();\n }\n if (left instanceof RegExp && right instanceof RegExp) {\n return left.source === right.source && left.flags === right.flags;\n }\n if (left instanceof Map && right instanceof Map) {\n return sameList([...left.entries()], [...right.entries()]);\n }\n if (left instanceof Set && right instanceof Set) {\n return sameList([...left.values()], [...right.values()]);\n }\n if (ArrayBuffer.isView(left) && ArrayBuffer.isView(right)) {\n return sameList(bytesOf(left), bytesOf(right));\n }\n if (Array.isArray(left) && Array.isArray(right)) {\n return sameList(left, right);\n }\n if (tag !== '[object Object]') return false;\n\n const keys = Object.keys(left);\n return (\n keys.length === Object.keys(right).length &&\n keys.every(\n key =>\n key in right && same(Reflect.get(left, key), Reflect.get(right, key)),\n )\n );\n}\n\n/**\n * The four matchers that assert on what a component asked the host to do.\n *\n * @remarks\n * Each takes the mock `renderWithTap` returns, so the assertion is\n * `expect(mock).toHaveToasted(…)` rather than `expect(component)`; anything else\n * throws a `TapError` carrying `TAP_TEST_TARGET_INVALID`. A failure names every\n * call that was recorded, so a wrong path or message reads without a debugger. The\n * vitest and jest presets register these, and both declare the four on the runner's\n * own `Matchers` interface, so `expect(mock).toHaveToasted` typechecks once the\n * preset is in the setup files.\n *\n * @example\n * ```ts\n * import '@tappify/extension-sdk/testing/vitest';\n * import { createTapMock } from '@tappify/extension-sdk/testing';\n * import { expect, it } from 'vitest';\n *\n * it('toasts when a release ships', () => {\n * const mock = createTapMock();\n * mock.tap.ui.toast('A release shipped', 'neutral');\n * expect(mock).toHaveToasted('A release shipped');\n * });\n * ```\n */\nexport const tapMatchers = {\n /** Passes when `tap.nav.push` was called with exactly that path. */\n toHaveNavigatedTo(received: unknown, path: string): MatcherResult {\n const mock = requireMock(received, 'toHaveNavigatedTo');\n const pass = mock.calls.navigations.includes(path);\n return {\n pass,\n message: () =>\n pass\n ? `Expected no navigation to ${path}, but tap.nav.push was called with it.`\n : `Expected a navigation to ${path}. tap.nav.push was called with: ${\n mock.calls.navigations.length === 0\n ? 'nothing'\n : mock.calls.navigations.join(', ')\n }.`,\n };\n },\n\n /** Passes when a toast matched the string exactly, or the pattern anywhere. */\n toHaveToasted(received: unknown, expected: string | RegExp): MatcherResult {\n const mock = requireMock(received, 'toHaveToasted');\n const messages = mock.calls.toasts.map(toast => toast.message);\n const pass = messages.some(message =>\n typeof expected === 'string'\n ? message === expected\n : expected.test(message),\n );\n return {\n pass,\n message: () =>\n pass\n ? `Expected no toast matching ${String(expected)}, but one was shown.`\n : `Expected a toast matching ${String(expected)}. Toasts shown: ${\n messages.length === 0 ? 'none' : messages.join(' | ')\n }.`,\n };\n },\n\n /**\n * Passes when `tap.actions.run` was called with that action, and with input\n * deep-equal to `input` when one is given.\n */\n toHaveRunAction(\n received: unknown,\n actionId: string,\n input?: unknown,\n ): MatcherResult {\n const mock = requireMock(received, 'toHaveRunAction');\n const runs = mock.calls.actions.filter(run => run.actionId === actionId);\n const pass =\n input === undefined\n ? runs.length > 0\n : runs.some(run => same(run.input, input));\n return {\n pass,\n message: () =>\n pass\n ? `Expected tap.actions.run(\"${actionId}\") not to be called.`\n : `Expected tap.actions.run(\"${actionId}\"${\n input === undefined ? '' : `, ${JSON.stringify(input)}`\n }). Runs recorded: ${\n mock.calls.actions.length === 0\n ? 'none'\n : JSON.stringify(mock.calls.actions)\n }.`,\n };\n },\n\n /**\n * Passes when the mock's storage holds a document deep-equal to that one in\n * that collection.\n */\n toHaveStored(\n received: unknown,\n collection: string,\n document: unknown,\n ): MatcherResult {\n const mock = requireMock(received, 'toHaveStored');\n const stored = mock.documents(collection);\n const pass = stored.some(candidate => same(candidate, document));\n return {\n pass,\n message: () =>\n pass\n ? `Expected \"${collection}\" not to hold ${JSON.stringify(document)}.`\n : `Expected \"${collection}\" to hold ${JSON.stringify(document)}. It holds: ${\n stored.length === 0 ? 'nothing' : JSON.stringify(stored)\n }.`,\n };\n },\n};\n\n/**\n * Registers the four matchers on a runner's `expect`.\n *\n * @remarks\n * The vitest and jest presets call this, so a suite that loads\n * `@tappify/extension-sdk/testing/vitest` or `.../testing/jest` as a setup file\n * needs nothing else. Call it yourself only in a suite that does not use a preset,\n * and once — registering twice replaces the same four names. It adds no types of\n * its own, so a suite without a preset declares the four on the runner's `Matchers`\n * interface itself.\n *\n * @example\n * ```ts\n * import { registerTapMatchers } from '@tappify/extension-sdk/testing';\n * import { expect } from 'vitest';\n *\n * registerTapMatchers(expect);\n * ```\n */\nexport function registerTapMatchers(target: MatcherTarget): void {\n target.extend(tapMatchers);\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TapContext
|
|
3
|
+
} from "./chunk-QHM7XNRK.mjs";
|
|
4
|
+
|
|
5
|
+
// src/host/provider.tsx
|
|
6
|
+
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
7
|
+
import { jsx } from "react/jsx-runtime";
|
|
8
|
+
function TapHostProvider({
|
|
9
|
+
tap,
|
|
10
|
+
children,
|
|
11
|
+
queryClient
|
|
12
|
+
}) {
|
|
13
|
+
const provided = /* @__PURE__ */ jsx(TapContext.Provider, { value: tap, children });
|
|
14
|
+
return queryClient === void 0 ? provided : /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children: provided });
|
|
15
|
+
}
|
|
16
|
+
function createHostQueryClient() {
|
|
17
|
+
return new QueryClient({
|
|
18
|
+
defaultOptions: { queries: { retry: false } }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
TapHostProvider,
|
|
24
|
+
createHostQueryClient
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-4C5Z3CIK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/provider.tsx"],"sourcesContent":["import { QueryClient, QueryClientProvider } from '@tanstack/react-query';\nimport type { ReactElement, ReactNode } from 'react';\nimport { TapContext } from '../client/context';\nimport type { Tap } from '../client/types';\n\nexport interface TapHostProviderProps {\n tap: Tap;\n children: ReactNode;\n /**\n * A host that already renders a QueryClientProvider leaves this out; a\n * standalone host such as the portal preview passes one from\n * `createHostQueryClient()` so the data hooks find a client.\n */\n queryClient?: QueryClient;\n}\n\nexport function TapHostProvider({\n tap,\n children,\n queryClient,\n}: TapHostProviderProps): ReactElement {\n const provided = (\n <TapContext.Provider value={tap}>{children}</TapContext.Provider>\n );\n\n return queryClient === undefined ? (\n provided\n ) : (\n <QueryClientProvider client={queryClient}>{provided}</QueryClientProvider>\n );\n}\n\n/** The query client a standalone host hands to `TapHostProvider`; reads never retry. */\nexport function createHostQueryClient(): QueryClient {\n return new QueryClient({\n defaultOptions: { queries: { retry: false } },\n });\n}\n"],"mappings":";;;;;AAAA,SAAS,aAAa,2BAA2B;AAsB7C;AANG,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AACrC,QAAM,WACJ,oBAAC,WAAW,UAAX,EAAoB,OAAO,KAAM,UAAS;AAG7C,SAAO,gBAAgB,SACrB,WAEA,oBAAC,uBAAoB,QAAQ,aAAc,oBAAS;AAExD;AAGO,SAAS,wBAAqC;AACnD,SAAO,IAAI,YAAY;AAAA,IACrB,gBAAgB,EAAE,SAAS,EAAE,OAAO,MAAM,EAAE;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkOPPYEA7Fcjs = require('./chunk-OPPYEA7F.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk2DBSVKAUcjs = require('./chunk-2DBSVKAU.cjs');
|
|
7
|
+
|
|
8
|
+
// src/client/hooks.ts
|
|
9
|
+
var _react = require('react');
|
|
10
|
+
function useTapSlice(key, select) {
|
|
11
|
+
const tap = _chunkOPPYEA7Fcjs.useTap.call(void 0, );
|
|
12
|
+
const subscribe = _react.useCallback.call(void 0,
|
|
13
|
+
(listener) => tap.__subscribe(key, listener),
|
|
14
|
+
[tap, key]
|
|
15
|
+
);
|
|
16
|
+
const snapshot = _react.useCallback.call(void 0, () => select(tap), [tap, select]);
|
|
17
|
+
return _react.useSyncExternalStore.call(void 0, subscribe, snapshot, snapshot);
|
|
18
|
+
}
|
|
19
|
+
var selectAuth = (tap) => tap.auth;
|
|
20
|
+
var selectProject = (tap) => tap.project;
|
|
21
|
+
var selectFilters = (tap) => tap.filters;
|
|
22
|
+
var selectTheme = (tap) => tap.theme;
|
|
23
|
+
var selectSize = (tap) => tap.ui.size;
|
|
24
|
+
var selectParams = (tap) => tap.params;
|
|
25
|
+
var selectContext = (tap) => tap.context;
|
|
26
|
+
function useTapAuth() {
|
|
27
|
+
return useTapSlice("auth", selectAuth);
|
|
28
|
+
}
|
|
29
|
+
function useTapProject() {
|
|
30
|
+
return useTapSlice("project", selectProject);
|
|
31
|
+
}
|
|
32
|
+
function useTapFilters() {
|
|
33
|
+
return useTapSlice("filters", selectFilters);
|
|
34
|
+
}
|
|
35
|
+
function useTapTheme() {
|
|
36
|
+
return useTapSlice("theme", selectTheme);
|
|
37
|
+
}
|
|
38
|
+
function useTapSize() {
|
|
39
|
+
return useTapSlice("size", selectSize);
|
|
40
|
+
}
|
|
41
|
+
function useTapParams() {
|
|
42
|
+
return useTapSlice("params", selectParams);
|
|
43
|
+
}
|
|
44
|
+
function useTapContext() {
|
|
45
|
+
return useTapSlice("context", selectContext);
|
|
46
|
+
}
|
|
47
|
+
function useTapState(key) {
|
|
48
|
+
const tap = _chunkOPPYEA7Fcjs.useTap.call(void 0, );
|
|
49
|
+
const subscribe = _react.useCallback.call(void 0,
|
|
50
|
+
(listener) => tap.__subscribe(`state:${key}`, listener),
|
|
51
|
+
[tap, key]
|
|
52
|
+
);
|
|
53
|
+
const snapshot = _react.useCallback.call(void 0, () => tap.state.get(key), [tap, key]);
|
|
54
|
+
const set = _react.useCallback.call(void 0,
|
|
55
|
+
(value2) => {
|
|
56
|
+
tap.state.set(key, value2);
|
|
57
|
+
},
|
|
58
|
+
[tap, key]
|
|
59
|
+
);
|
|
60
|
+
const value = _react.useSyncExternalStore.call(void 0, subscribe, snapshot, snapshot);
|
|
61
|
+
return [value, set];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/client/query.ts
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
var _reactquery = require('@tanstack/react-query');
|
|
69
|
+
|
|
70
|
+
var STALE_TIME_MS = 3e4;
|
|
71
|
+
function dataQueryKey(installId, query, filters) {
|
|
72
|
+
return ["ext", installId, "data", query, filters];
|
|
73
|
+
}
|
|
74
|
+
function procedureQueryKey(installId, name, input, filters) {
|
|
75
|
+
return ["ext", installId, "proc", name, input, filters];
|
|
76
|
+
}
|
|
77
|
+
function storageQueryKey(installId, collection) {
|
|
78
|
+
return ["ext", installId, "storage", collection];
|
|
79
|
+
}
|
|
80
|
+
function installPrefix(installId) {
|
|
81
|
+
return ["ext", installId];
|
|
82
|
+
}
|
|
83
|
+
function procedurePrefix(installId, name) {
|
|
84
|
+
return ["ext", installId, "proc", name];
|
|
85
|
+
}
|
|
86
|
+
function useInvalidateOn(tap, client, queryKey, events) {
|
|
87
|
+
const eventsRef = _react.useRef.call(void 0, events);
|
|
88
|
+
const keyRef = _react.useRef.call(void 0, queryKey);
|
|
89
|
+
_react.useEffect.call(void 0, () => {
|
|
90
|
+
eventsRef.current = events;
|
|
91
|
+
keyRef.current = queryKey;
|
|
92
|
+
});
|
|
93
|
+
const eventSignature = (_nullishCoalesce(events, () => ( []))).join(",");
|
|
94
|
+
_react.useEffect.call(void 0, () => {
|
|
95
|
+
const names = _nullishCoalesce(eventsRef.current, () => ( []));
|
|
96
|
+
if (names.length === 0) return;
|
|
97
|
+
const unsubscribes = names.map(
|
|
98
|
+
(name) => tap.data.subscribe(name, () => {
|
|
99
|
+
void client.invalidateQueries({ queryKey: keyRef.current });
|
|
100
|
+
})
|
|
101
|
+
);
|
|
102
|
+
return () => {
|
|
103
|
+
for (const unsubscribe of unsubscribes) unsubscribe();
|
|
104
|
+
};
|
|
105
|
+
}, [tap, client, eventSignature]);
|
|
106
|
+
}
|
|
107
|
+
function useHostQueryClient() {
|
|
108
|
+
try {
|
|
109
|
+
return _reactquery.useQueryClient.call(void 0, );
|
|
110
|
+
} catch (e) {
|
|
111
|
+
throw new (0, _chunk2DBSVKAUcjs.TapError)(
|
|
112
|
+
"TAP_NO_QUERY_CLIENT",
|
|
113
|
+
"The Tappify host provides the query client. This hook runs only inside a Tappify mount \u2014 render the component from an entry declared in tappify.extension.json, or wrap it in renderWithTap() from @tappify/extension-sdk/testing."
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function useTapQuery(query, options = {}) {
|
|
118
|
+
const tap = _chunkOPPYEA7Fcjs.useTap.call(void 0, );
|
|
119
|
+
const client = useHostQueryClient();
|
|
120
|
+
const filters = useTapFilters();
|
|
121
|
+
const queryKey = dataQueryKey(tap.extension.installId, query, filters);
|
|
122
|
+
const result = _reactquery.useQuery.call(void 0, {
|
|
123
|
+
queryKey,
|
|
124
|
+
queryFn: () => tap.data.query(query),
|
|
125
|
+
enabled: _nullishCoalesce(options.enabled, () => ( true)),
|
|
126
|
+
staleTime: STALE_TIME_MS,
|
|
127
|
+
retry: false
|
|
128
|
+
});
|
|
129
|
+
useInvalidateOn(tap, client, queryKey, options.invalidateOn);
|
|
130
|
+
const resultRefetch = result.refetch;
|
|
131
|
+
const refetch = _react.useCallback.call(void 0, () => {
|
|
132
|
+
void resultRefetch();
|
|
133
|
+
}, [resultRefetch]);
|
|
134
|
+
return {
|
|
135
|
+
data: result.data,
|
|
136
|
+
error: result.error,
|
|
137
|
+
isLoading: result.isLoading,
|
|
138
|
+
refetch
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function useTapServer(name, input, options = {}) {
|
|
142
|
+
const tap = _chunkOPPYEA7Fcjs.useTap.call(void 0, );
|
|
143
|
+
const client = useHostQueryClient();
|
|
144
|
+
const filters = useTapFilters();
|
|
145
|
+
const queryKey = procedureQueryKey(
|
|
146
|
+
tap.extension.installId,
|
|
147
|
+
name,
|
|
148
|
+
input,
|
|
149
|
+
filters
|
|
150
|
+
);
|
|
151
|
+
const procedure = tap.server[name];
|
|
152
|
+
if (typeof procedure !== "function") {
|
|
153
|
+
throw new (0, _chunk2DBSVKAUcjs.TapError)(
|
|
154
|
+
"TAP_UNKNOWN_PROCEDURE",
|
|
155
|
+
`Procedure "${name}" is not declared. Add it under server.procedures in tappify.extension.json, then run \`tappify extension types\`.`
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
const result = _reactquery.useQuery.call(void 0, {
|
|
159
|
+
queryKey,
|
|
160
|
+
queryFn: () => procedure(input),
|
|
161
|
+
enabled: _nullishCoalesce(options.enabled, () => ( true)),
|
|
162
|
+
staleTime: STALE_TIME_MS,
|
|
163
|
+
retry: false
|
|
164
|
+
});
|
|
165
|
+
useInvalidateOn(tap, client, queryKey, options.invalidateOn);
|
|
166
|
+
const resultRefetch = result.refetch;
|
|
167
|
+
const refetch = _react.useCallback.call(void 0, () => {
|
|
168
|
+
void resultRefetch();
|
|
169
|
+
}, [resultRefetch]);
|
|
170
|
+
return {
|
|
171
|
+
data: result.data,
|
|
172
|
+
error: result.error,
|
|
173
|
+
isLoading: result.isLoading,
|
|
174
|
+
refetch
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function isSingletonHandle(value) {
|
|
178
|
+
return typeof value === "object" && value !== null && "get" in value && "set" in value && "patch" in value && typeof value.get === "function" && typeof value.set === "function" && typeof value.patch === "function";
|
|
179
|
+
}
|
|
180
|
+
function asSingleton(handle, collection) {
|
|
181
|
+
if (isSingletonHandle(handle)) return handle;
|
|
182
|
+
throw new (0, _chunk2DBSVKAUcjs.TapError)(
|
|
183
|
+
"TAP_UNKNOWN_COLLECTION",
|
|
184
|
+
`useTapStorage("${collection}") reads a singleton collection. Declare it with "singleton": true in tappify.extension.json, or read an id-keyed collection with tap.storage.${collection}.list().`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
function useTapStorage(collection) {
|
|
188
|
+
const tap = _chunkOPPYEA7Fcjs.useTap.call(void 0, );
|
|
189
|
+
const client = useHostQueryClient();
|
|
190
|
+
const queryKey = storageQueryKey(tap.extension.installId, collection);
|
|
191
|
+
const handle = asSingleton(tap.storage[collection], collection);
|
|
192
|
+
const result = _reactquery.useQuery.call(void 0, {
|
|
193
|
+
queryKey,
|
|
194
|
+
queryFn: () => handle.get(),
|
|
195
|
+
staleTime: STALE_TIME_MS,
|
|
196
|
+
retry: false
|
|
197
|
+
});
|
|
198
|
+
const installId = tap.extension.installId;
|
|
199
|
+
const invalidate = _react.useCallback.call(void 0, () => {
|
|
200
|
+
void client.invalidateQueries({
|
|
201
|
+
queryKey: storageQueryKey(installId, collection)
|
|
202
|
+
});
|
|
203
|
+
}, [client, installId, collection]);
|
|
204
|
+
_react.useEffect.call(void 0,
|
|
205
|
+
() => tap.__subscribe(`storage:${collection}`, invalidate),
|
|
206
|
+
[tap, collection, invalidate]
|
|
207
|
+
);
|
|
208
|
+
const save = _react.useCallback.call(void 0,
|
|
209
|
+
async (document) => {
|
|
210
|
+
await handle.set(document);
|
|
211
|
+
},
|
|
212
|
+
[handle]
|
|
213
|
+
);
|
|
214
|
+
const patch = _react.useCallback.call(void 0,
|
|
215
|
+
async (partial) => handle.patch(partial),
|
|
216
|
+
[handle]
|
|
217
|
+
);
|
|
218
|
+
const resultRefetch = result.refetch;
|
|
219
|
+
const refetch = _react.useCallback.call(void 0, () => {
|
|
220
|
+
void resultRefetch();
|
|
221
|
+
}, [resultRefetch]);
|
|
222
|
+
return {
|
|
223
|
+
data: result.data,
|
|
224
|
+
error: result.error,
|
|
225
|
+
isLoading: result.isLoading,
|
|
226
|
+
refetch,
|
|
227
|
+
save,
|
|
228
|
+
patch
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
exports.useTapAuth = useTapAuth; exports.useTapProject = useTapProject; exports.useTapFilters = useTapFilters; exports.useTapTheme = useTapTheme; exports.useTapSize = useTapSize; exports.useTapParams = useTapParams; exports.useTapContext = useTapContext; exports.useTapState = useTapState; exports.dataQueryKey = dataQueryKey; exports.procedureQueryKey = procedureQueryKey; exports.storageQueryKey = storageQueryKey; exports.installPrefix = installPrefix; exports.procedurePrefix = procedurePrefix; exports.useTapQuery = useTapQuery; exports.useTapServer = useTapServer; exports.useTapStorage = useTapStorage;
|
|
250
|
+
//# sourceMappingURL=chunk-5AAPD5WV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/vulakh/Desktop/Work/Tappify/extension-sdk/dist/chunk-5AAPD5WV.cjs","../src/client/hooks.ts","../src/client/query.ts"],"names":["useCallback"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACPA,8BAAkD;AAIlD,SAAS,WAAA,CAAe,GAAA,EAAmB,MAAA,EAA4B;AACrE,EAAA,MAAM,IAAA,EAAM,sCAAA,CAAO;AAEnB,EAAA,MAAM,UAAA,EAAY,gCAAA;AAAA,IAChB,CAAC,QAAA,EAAA,GAAyB,GAAA,CAAI,WAAA,CAAY,GAAA,EAAK,QAAQ,CAAA;AAAA,IACvD,CAAC,GAAA,EAAK,GAAG;AAAA,EACX,CAAA;AACA,EAAA,MAAM,SAAA,EAAW,gCAAA,CAAY,EAAA,GAAM,MAAA,CAAO,GAAG,CAAA,EAAG,CAAC,GAAA,EAAK,MAAM,CAAC,CAAA;AAE7D,EAAA,OAAO,yCAAA,SAAqB,EAAW,QAAA,EAAU,QAAQ,CAAA;AAC3D;AAEA,IAAM,WAAA,EAAa,CAAC,GAAA,EAAA,GAA0B,GAAA,CAAI,IAAA;AAClD,IAAM,cAAA,EAAgB,CAAC,GAAA,EAAA,GAA6B,G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AAEV,EAAA;AACK,EAAA;AACb,IAAA;AACH,EAAA;AAEX,EAAA;AACQ,IAAA;AACC,IAAA;AACI,IAAA;AAClB,IAAA;AACF,EAAA;AACF;AAEwE;AAGpE,EAAA;AAQJ;AAE8E;AACnC,EAAA;AAE/B,EAAA;AACR,IAAA;AAC4B,IAAA;AAC9B,EAAA;AACF;AAkC6C;AAGxB,EAAA;AACe,EAAA;AACG,EAAA;AACY,EAAA;AAEzB,EAAA;AACtB,IAAA;AAC0B,IAAA;AACf,IAAA;AACJ,IAAA;AACR,EAAA;AAE+B,EAAA;AACK,EAAA;AACL,IAAA;AACS,MAAA;AACtC,IAAA;AAC+B,EAAA;AAElC,EAAA;AAC6C,IAAA;AACf,IAAA;AAC9B,EAAA;AAEaA,EAAAA;AACmB,IAAA;AACH,MAAA;AAC3B,IAAA;AACO,IAAA;AACT,EAAA;AAEcA,EAAAA;AAC8C,IAAA;AACnD,IAAA;AACT,EAAA;AAE6B,EAAA;AACK,EAAA;AACb,IAAA;AACH,EAAA;AAEX,EAAA;AACQ,IAAA;AACC,IAAA;AACI,IAAA;AAClB,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;AFrP+C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/vulakh/Desktop/Work/Tappify/extension-sdk/dist/chunk-5AAPD5WV.cjs","sourcesContent":[null,"import { useCallback, useSyncExternalStore } from 'react';\nimport { useTap } from './context';\nimport type { Tap, TapChangeKey, TapFilters, TapSize } from './types';\n\nfunction useTapSlice<T>(key: TapChangeKey, select: (tap: Tap) => T): T {\n const tap = useTap();\n\n const subscribe = useCallback(\n (listener: () => void) => tap.__subscribe(key, listener),\n [tap, key],\n );\n const snapshot = useCallback(() => select(tap), [tap, select]);\n\n return useSyncExternalStore(subscribe, snapshot, snapshot);\n}\n\nconst selectAuth = (tap: Tap): Tap['auth'] => tap.auth;\nconst selectProject = (tap: Tap): Tap['project'] => tap.project;\nconst selectFilters = (tap: Tap): TapFilters => tap.filters;\nconst selectTheme = (tap: Tap): Tap['theme'] => tap.theme;\nconst selectSize = (tap: Tap): TapSize => tap.ui.size;\nconst selectParams = (tap: Tap): Record<string, string> => tap.params;\nconst selectContext = (tap: Tap): Record<string, unknown> => tap.context;\n\n/**\n * Returns the install token, the signed-in teammate, the workspace id, the\n * granted scopes and `can(scope)`.\n *\n * @remarks\n * Re-renders the component when the host rotates the install token, and when the\n * signed-in teammate's role arrives after the mount. `scopes` and `can` report the\n * grant the mount was built with. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { TapEmptyState, useTapAuth } from '@tappify/extension-sdk';\n *\n * function RevenuePanel() {\n * const auth = useTapAuth();\n * if (!auth.can('revenue:read')) {\n * return <TapEmptyState title=\"Revenue is not shared with this extension\" />;\n * }\n * return <span>Signed in as {auth.user.id}</span>;\n * }\n * ```\n */\nexport function useTapAuth(): Tap['auth'] {\n return useTapSlice('auth', selectAuth);\n}\n\n/**\n * Returns the project the mount renders in, with its apps, releases and tracked\n * keywords.\n *\n * @remarks\n * Re-renders when the host loads or reloads the project. Throws\n * `TAP_OUTSIDE_HOST` outside a mount. An extension installed on the workspace\n * rather than a project still renders inside one project at a time.\n *\n * @example\n * ```tsx\n * import { useTapProject } from '@tappify/extension-sdk';\n *\n * function Platforms() {\n * const project = useTapProject();\n * return <span>{project.name} ships to {project.platforms.join(' and ')}</span>;\n * }\n * ```\n */\nexport function useTapProject(): Tap['project'] {\n return useTapSlice('project', selectProject);\n}\n\n/**\n * Returns the date range, platform and country the owner's filter bar is set to.\n *\n * @remarks\n * Re-renders on every filter change, which is how a surface follows the owner's\n * picker. Pass `range` into a `series`, `reviews`, `crashes` or `revenue` query\n * yourself; the host adds only the country to a data read, while a procedure call\n * carries all three. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapFilters, useTapQuery } from '@tappify/extension-sdk';\n *\n * function Downloads() {\n * const filters = useTapFilters();\n * const downloads = useTapQuery({\n * kind: 'series',\n * metric: 'downloads',\n * range: filters.range,\n * });\n * return <span>{downloads.data?.points.length ?? 0} days</span>;\n * }\n * ```\n */\nexport function useTapFilters(): TapFilters {\n return useTapSlice('filters', selectFilters);\n}\n\n/**\n * Returns the mode the host is drawing in, as `{ mode: 'light' | 'dark' }`.\n *\n * @remarks\n * Re-renders when the owner switches theme. The host's CSS variables already\n * follow the theme, so reach for this only where a component has to branch in\n * code rather than restyle, such as a chart's series colours. Throws\n * `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapTheme } from '@tappify/extension-sdk';\n *\n * function SeriesLine() {\n * const theme = useTapTheme();\n * const stroke = theme.mode === 'dark' ? '#a5b4fc' : '#4f46e5';\n * return <svg><line x1=\"0\" y1=\"0\" x2=\"40\" y2=\"10\" stroke={stroke} /></svg>;\n * }\n * ```\n */\nexport function useTapTheme(): Tap['theme'] {\n return useTapSlice('theme', selectTheme);\n}\n\n/**\n * Returns how much room the mount has: `slot`, `panel` or `page`.\n *\n * @remarks\n * Expanding a widget mounts a second copy of the component in the panel rather\n * than resizing the one in the slot, so the change this hook reports is the\n * panel's own Widen and Narrow toggle moving between `panel` and `page`. Size\n * against the mount with a container query where CSS can do the work; this hook is\n * for the cases that need different markup. Throws `TAP_OUTSIDE_HOST` outside a\n * mount.\n *\n * @example\n * ```tsx\n * import { TapTable, useTapSize } from '@tappify/extension-sdk';\n *\n * function Keywords({ rows }: { rows: { term: string }[] }) {\n * const size = useTapSize();\n * const shown = size === 'slot' ? rows.slice(0, 3) : rows;\n * return (\n * <TapTable\n * columns={[{ key: 'term', label: 'Term' }]}\n * rows={shown}\n * rowKey={row => row.term}\n * />\n * );\n * }\n * ```\n */\nexport function useTapSize(): TapSize {\n return useTapSlice('size', selectSize);\n}\n\n/**\n * Returns the route of the extension's own page: the page id, the whole sub-path,\n * and one key per segment.\n *\n * @remarks\n * The host builds `pageId`, `path` and then `0`, `1` and so on, one per segment of\n * the sub-path. Only a page entry is routed, so this is empty for a widget, a tab,\n * a row action and a settings panel. Re-renders when the owner navigates inside the\n * page. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapParams } from '@tappify/extension-sdk';\n *\n * function FunnelDetail() {\n * const params = useTapParams();\n * const funnelId = params['1'];\n * return <span>{funnelId ?? params.path}</span>;\n * }\n * ```\n */\nexport function useTapParams(): Record<string, string> {\n return useTapSlice('params', selectParams);\n}\n\n/**\n * Returns what the surface handed the mount: the payload Expand carried in, or\n * the row behind a row action.\n *\n * @remarks\n * Re-renders when the host hands the mount a new context. A row action reads the\n * row from its own `row` prop as well; this hook is the same value for a\n * component further down the tree. Throws `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { useTapContext } from '@tappify/extension-sdk';\n *\n * function ContextNote() {\n * const context = useTapContext();\n * const reviewId = context.reviewId;\n * return <span>{typeof reviewId === 'string' ? reviewId : 'No review'}</span>;\n * }\n * ```\n */\nexport function useTapContext(): Record<string, unknown> {\n return useTapSlice('context', selectContext);\n}\n\n/**\n * Returns one value from the in-memory store every mount of the install shares,\n * with a setter for it.\n *\n * @remarks\n * The value is `undefined` until something sets it, and setting it re-renders\n * every mount reading the same key, including a sibling widget and the expand\n * panel. The store lives in the browser session: it is not persisted, not shared\n * between teammates or tabs, and never reaches Tappify or your server — use\n * `useTapStorage` for a value that has to come back tomorrow. Throws\n * `TAP_OUTSIDE_HOST` outside a mount.\n *\n * @example\n * ```tsx\n * import { TapButton, useTapState } from '@tappify/extension-sdk';\n *\n * function StepPicker() {\n * const [step, setStep] = useTapState<string>('selectedStep');\n * return (\n * <TapButton onClick={() => setStep('install')}>\n * {step ?? 'Pick a step'}\n * </TapButton>\n * );\n * }\n * ```\n */\nexport function useTapState<T>(\n key: string,\n): [T | undefined, (value: T) => void] {\n const tap = useTap();\n\n const subscribe = useCallback(\n (listener: () => void) => tap.__subscribe(`state:${key}`, listener),\n [tap, key],\n );\n const snapshot = useCallback(() => tap.state.get<T>(key), [tap, key]);\n const set = useCallback(\n (value: T) => {\n tap.state.set(key, value);\n },\n [tap, key],\n );\n\n const value = useSyncExternalStore(subscribe, snapshot, snapshot);\n return [value, set];\n}\n","import {\n useQuery,\n useQueryClient,\n type QueryClient,\n} from '@tanstack/react-query';\nimport { useCallback, useEffect, useRef } from 'react';\nimport { useTap } from './context';\nimport { TapError } from './errors';\nimport { useTapFilters } from './hooks';\nimport type {\n Tap,\n TapFilters,\n TapHostEvents,\n TapProcedureInput,\n TapProcedureName,\n TapProcedureOutput,\n TapQuery,\n TapResult,\n TapSingleton,\n TapSingletonDocument,\n TapSingletonName,\n} from './types';\n\nconst STALE_TIME_MS = 30_000;\n\n/** The third argument of `useTapQuery` and `useTapServer`. */\nexport interface TapQueryOptions {\n /** Holds the call back while this is `false`. Defaults to `true`. */\n enabled?: boolean;\n /** Tappify events that mark this result stale and refetch it when they arrive. */\n invalidateOn?: (keyof TapHostEvents)[];\n}\n\n/** What `useTapQuery` and `useTapServer` return. */\nexport interface TapQueryResult<T> {\n /**\n * `undefined` until the first answer for this key arrives. A later call that\n * fails leaves the last answer in place and only sets `error`, so branch on\n * `error` to detect a failure, never on `data`.\n */\n data: T | undefined;\n error: Error | null;\n /** `true` only while the first answer for this key is in flight. */\n isLoading: boolean;\n /** Asks again now, whether or not the cached answer has gone stale. */\n refetch(): void;\n}\n\n/** What `useTapStorage` returns: a read of the document, plus the two writes. */\nexport interface TapStorageResult<T> extends TapQueryResult<T | null> {\n /** Replaces the whole document. */\n save(document: T): Promise<void>;\n /** Merges the fields in and resolves to the merged document. */\n patch(partial: Partial<T>): Promise<T>;\n}\n\n/**\n * Builds the cache key `useTapQuery` reads a Tappify data query under.\n *\n * @remarks\n * The key carries the install, the query and the filters behind it, so two mounts\n * asking for the same numbers share one request. Call it only to reach the query\n * cache directly; the hooks build their own keys.\n *\n * @example\n * ```ts\n * import { dataQueryKey } from '@tappify/extension-sdk';\n *\n * const key = dataQueryKey('ins_test', { kind: 'keywords' }, {\n * range: { from: '2026-09-01', to: '2026-09-08' },\n * platform: 'all',\n * country: 'all',\n * });\n * ```\n */\nexport function dataQueryKey(\n installId: string,\n query: TapQuery,\n filters: TapFilters,\n): unknown[] {\n return ['ext', installId, 'data', query, filters];\n}\n\n/**\n * Builds the cache key `useTapServer` reads one procedure call under.\n *\n * @remarks\n * The input and the filters are part of the key, so the same procedure called\n * with different input caches separately. Call it only to reach the query cache\n * directly.\n *\n * @example\n * ```ts\n * import { procedureQueryKey } from '@tappify/extension-sdk';\n *\n * const key = procedureQueryKey('ins_test', 'getSummary', { days: 7 }, {\n * range: { from: '2026-09-01', to: '2026-09-08' },\n * platform: 'all',\n * country: 'all',\n * });\n * ```\n */\nexport function procedureQueryKey(\n installId: string,\n name: string,\n input: unknown,\n filters: TapFilters,\n): unknown[] {\n return ['ext', installId, 'proc', name, input, filters];\n}\n\n/**\n * Builds the cache key `useTapStorage` reads one collection's document under.\n *\n * @remarks\n * The filters are not part of the key, because a stored document does not depend\n * on them. Call it only to reach the query cache directly.\n *\n * @example\n * ```ts\n * import { storageQueryKey } from '@tappify/extension-sdk';\n *\n * const key = storageQueryKey('ins_test', 'preferences');\n * ```\n */\nexport function storageQueryKey(\n installId: string,\n collection: string,\n): unknown[] {\n return ['ext', installId, 'storage', collection];\n}\n\n/**\n * Builds the key prefix every cached answer of one install sits under.\n *\n * @remarks\n * This is the prefix `tap.invalidate()` with no name invalidates.\n *\n * @example\n * ```ts\n * import { installPrefix } from '@tappify/extension-sdk';\n *\n * const prefix = installPrefix('ins_test');\n * ```\n */\nexport function installPrefix(installId: string): unknown[] {\n return ['ext', installId];\n}\n\n/**\n * Builds the key prefix every cached call of one procedure sits under, whatever\n * its input.\n *\n * @remarks\n * This is the prefix `tap.invalidate(name)` invalidates.\n *\n * @example\n * ```ts\n * import { procedurePrefix } from '@tappify/extension-sdk';\n *\n * const prefix = procedurePrefix('ins_test', 'getSummary');\n * ```\n */\nexport function procedurePrefix(installId: string, name: string): unknown[] {\n return ['ext', installId, 'proc', name];\n}\n\nfunction useInvalidateOn(\n tap: Tap,\n client: QueryClient,\n queryKey: unknown[],\n events: (keyof TapHostEvents)[] | undefined,\n): void {\n const eventsRef = useRef(events);\n const keyRef = useRef(queryKey);\n\n useEffect(() => {\n eventsRef.current = events;\n keyRef.current = queryKey;\n });\n\n const eventSignature = (events ?? []).join(',');\n\n useEffect(() => {\n const names = eventsRef.current ?? [];\n if (names.length === 0) return;\n\n const unsubscribes = names.map(name =>\n tap.data.subscribe(name, () => {\n void client.invalidateQueries({ queryKey: keyRef.current });\n }),\n );\n\n return () => {\n for (const unsubscribe of unsubscribes) unsubscribe();\n };\n }, [tap, client, eventSignature]);\n}\n\nfunction useHostQueryClient(): QueryClient {\n try {\n return useQueryClient();\n } catch {\n throw new TapError(\n 'TAP_NO_QUERY_CLIENT',\n 'The Tappify host provides the query client. This hook runs only inside a Tappify mount — render the component from an entry declared in tappify.extension.json, or wrap it in renderWithTap() from @tappify/extension-sdk/testing.',\n );\n }\n}\n\n/**\n * Reads one query's worth of the owner's Tappify data, cached per install, query\n * and filter bar.\n *\n * @remarks\n * Each kind needs its own scope — `project` needs `projects:read`, `series` needs\n * `analytics:read`, `keywords` and `listing` need `store.metadata:read`, and\n * `reviews`, `crashes` and `revenue` need their own. A kind the install has not\n * granted comes back as a `TapError` with code `TAP_SCOPE_MISSING` in `error`. An\n * answer stays fresh for 30 seconds and a failed read is not retried, so\n * `refetch` is yours to call. The host adds only the country filter to the read:\n * pass `range` into a `series`, `reviews`, `crashes` or `revenue` query yourself,\n * and `platform` into a `series` query, which is the only kind that takes one.\n * Throws `TAP_NO_QUERY_CLIENT` when no Tappify mount provides the query client.\n *\n * @example\n * ```tsx\n * import { TapStat, useTapFilters, useTapQuery } from '@tappify/extension-sdk';\n *\n * function Downloads() {\n * const filters = useTapFilters();\n * const downloads = useTapQuery(\n * { kind: 'series', metric: 'downloads', range: filters.range },\n * { invalidateOn: ['release.shipped'] },\n * );\n * const points = downloads.data?.points ?? [];\n * const total = points.reduce((sum, point) => sum + point.value, 0);\n * return <TapStat label=\"Downloads\" value={total} />;\n * }\n * ```\n *\n * @example\n * ```tsx\n * import { TapTable, useTapQuery } from '@tappify/extension-sdk';\n *\n * function Keywords() {\n * const keywords = useTapQuery({ kind: 'keywords' });\n * return (\n * <TapTable\n * columns={[\n * { key: 'term', label: 'Term' },\n * { key: 'position', label: 'Rank', align: 'end' },\n * ]}\n * rows={keywords.data?.keywords ?? []}\n * rowKey={keyword => keyword.id}\n * />\n * );\n * }\n * ```\n */\nexport function useTapQuery<Q extends TapQuery>(\n query: Q,\n options: TapQueryOptions = {},\n): TapQueryResult<TapResult<Q>> {\n const tap = useTap();\n const client = useHostQueryClient();\n const filters = useTapFilters();\n const queryKey = dataQueryKey(tap.extension.installId, query, filters);\n\n const result = useQuery({\n queryKey,\n queryFn: () => tap.data.query(query),\n enabled: options.enabled ?? true,\n staleTime: STALE_TIME_MS,\n retry: false,\n });\n\n useInvalidateOn(tap, client, queryKey, options.invalidateOn);\n\n const resultRefetch = result.refetch;\n const refetch = useCallback(() => {\n void resultRefetch();\n }, [resultRefetch]);\n\n return {\n data: result.data,\n error: result.error,\n isLoading: result.isLoading,\n refetch,\n };\n}\n\n/**\n * Calls one procedure on your own server, cached per install, name, input and\n * filter bar.\n *\n * @remarks\n * The name and the input are narrowed by the `TapProcedureMap` augmentation\n * `tappify extension types` writes, so a procedure the manifest does not declare\n * does not compile; at runtime a name the host has no route for throws\n * `TAP_UNKNOWN_PROCEDURE`. The call carries the whole filter bar for you. An\n * answer stays fresh for 30 seconds and a failure is not retried; an error your\n * server threw arrives as a `TapServerError` with your own `code`. Throws\n * `TAP_NO_QUERY_CLIENT` when no Tappify mount provides the query client.\n *\n * @example\n * ```tsx\n * import { TapButton, TapErrorState, useTapFilters, useTapServer } from '@tappify/extension-sdk';\n *\n * function Summary() {\n * const filters = useTapFilters();\n * const summary = useTapServer(\n * 'getSummary',\n * { days: 7, platform: filters.platform },\n * { invalidateOn: ['settings.changed'] },\n * );\n * if (summary.error !== null) {\n * return <TapErrorState title=\"The summary did not load\" description={summary.error.message} />;\n * }\n * return <TapButton loading={summary.isLoading} onClick={summary.refetch}>Refresh</TapButton>;\n * }\n * ```\n */\nexport function useTapServer<N extends TapProcedureName>(\n name: N,\n input: TapProcedureInput<N>,\n options: TapQueryOptions = {},\n): TapQueryResult<TapProcedureOutput<N>> {\n const tap = useTap();\n const client = useHostQueryClient();\n const filters = useTapFilters();\n const queryKey = procedureQueryKey(\n tap.extension.installId,\n name,\n input,\n filters,\n );\n const procedure = tap.server[name];\n\n if (typeof procedure !== 'function') {\n throw new TapError(\n 'TAP_UNKNOWN_PROCEDURE',\n `Procedure \"${name}\" is not declared. Add it under server.procedures in tappify.extension.json, then run \\`tappify extension types\\`.`,\n );\n }\n\n const result = useQuery({\n queryKey,\n queryFn: () => procedure(input),\n enabled: options.enabled ?? true,\n staleTime: STALE_TIME_MS,\n retry: false,\n });\n\n useInvalidateOn(tap, client, queryKey, options.invalidateOn);\n\n const resultRefetch = result.refetch;\n const refetch = useCallback(() => {\n void resultRefetch();\n }, [resultRefetch]);\n\n return {\n data: result.data,\n error: result.error,\n isLoading: result.isLoading,\n refetch,\n };\n}\n\nfunction isSingletonHandle<T>(value: unknown): value is TapSingleton<T> {\n return (\n typeof value === 'object' &&\n value !== null &&\n 'get' in value &&\n 'set' in value &&\n 'patch' in value &&\n typeof value.get === 'function' &&\n typeof value.set === 'function' &&\n typeof value.patch === 'function'\n );\n}\n\nfunction asSingleton<T>(handle: unknown, collection: string): TapSingleton<T> {\n if (isSingletonHandle<T>(handle)) return handle;\n\n throw new TapError(\n 'TAP_UNKNOWN_COLLECTION',\n `useTapStorage(\"${collection}\") reads a singleton collection. Declare it with \"singleton\": true in tappify.extension.json, or read an id-keyed collection with tap.storage.${collection}.list().`,\n );\n}\n\n/**\n * Reads and writes the one document a singleton storage collection holds.\n *\n * @remarks\n * The argument is a collection name from the `TapStorageMap` augmentation\n * `tappify extension types` writes, and the collection has to be declared with\n * `\"singleton\": true`; an id-keyed collection throws `TAP_UNKNOWN_COLLECTION`,\n * with the `tap.storage.<name>.list()` path in the message. `data` is `undefined`\n * while the first read is in flight and `null` until the document is first\n * written. Every storage call needs the `storage:write` scope, reads included, and\n * rejects with `TAP_SCOPE_MISSING` without it. A write from another mount or\n * another browser tab of the same install refetches this one.\n *\n * @example\n * ```tsx\n * import { TapButton, useTapStorage } from '@tappify/extension-sdk';\n *\n * function CompactToggle() {\n * const preferences = useTapStorage('preferences');\n * return (\n * <TapButton\n * loading={preferences.isLoading}\n * onClick={() => void preferences.patch({ compact: true })}\n * >\n * Compact\n * </TapButton>\n * );\n * }\n * ```\n */\nexport function useTapStorage<C extends TapSingletonName>(\n collection: C,\n): TapStorageResult<TapSingletonDocument<C>> {\n type Document = TapSingletonDocument<C>;\n\n const tap = useTap();\n const client = useHostQueryClient();\n const queryKey = storageQueryKey(tap.extension.installId, collection);\n const handle = asSingleton<Document>(tap.storage[collection], collection);\n\n const result = useQuery({\n queryKey,\n queryFn: () => handle.get(),\n staleTime: STALE_TIME_MS,\n retry: false,\n });\n\n const installId = tap.extension.installId;\n const invalidate = useCallback(() => {\n void client.invalidateQueries({\n queryKey: storageQueryKey(installId, collection),\n });\n }, [client, installId, collection]);\n\n useEffect(\n () => tap.__subscribe(`storage:${collection}`, invalidate),\n [tap, collection, invalidate],\n );\n\n const save = useCallback(\n async (document: Document) => {\n await handle.set(document);\n },\n [handle],\n );\n\n const patch = useCallback(\n async (partial: Partial<Document>) => handle.patch(partial),\n [handle],\n );\n\n const resultRefetch = result.refetch;\n const refetch = useCallback(() => {\n void resultRefetch();\n }, [resultRefetch]);\n\n return {\n data: result.data,\n error: result.error,\n isLoading: result.isLoading,\n refetch,\n save,\n patch,\n };\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkOPPYEA7Fcjs = require('./chunk-OPPYEA7F.cjs');
|
|
4
|
+
|
|
5
|
+
// src/host/provider.tsx
|
|
6
|
+
var _reactquery = require('@tanstack/react-query');
|
|
7
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
8
|
+
function TapHostProvider({
|
|
9
|
+
tap,
|
|
10
|
+
children,
|
|
11
|
+
queryClient
|
|
12
|
+
}) {
|
|
13
|
+
const provided = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOPPYEA7Fcjs.TapContext.Provider, { value: tap, children });
|
|
14
|
+
return queryClient === void 0 ? provided : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _reactquery.QueryClientProvider, { client: queryClient, children: provided });
|
|
15
|
+
}
|
|
16
|
+
function createHostQueryClient() {
|
|
17
|
+
return new (0, _reactquery.QueryClient)({
|
|
18
|
+
defaultOptions: { queries: { retry: false } }
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
exports.TapHostProvider = TapHostProvider; exports.createHostQueryClient = createHostQueryClient;
|
|
26
|
+
//# sourceMappingURL=chunk-7KIKOH5H.cjs.map
|