@metabase/client 0.0.0-stage → 0.1.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/CHANGELOG.md +7 -0
- package/LICENSE +661 -0
- package/README.md +488 -2
- package/dist/auth/credential.d.ts +2 -0
- package/dist/auth/credential.js +61 -0
- package/dist/auth/oauth-login.d.ts +2 -0
- package/dist/auth/oauth-login.js +2 -0
- package/dist/auth/oauth-session.d.ts +2 -0
- package/dist/auth/oauth-session.js +31 -0
- package/dist/card-B6merEUN.d.ts +1392 -0
- package/dist/card-BZx4NSr-.d.ts +33 -0
- package/dist/client-DNRvXFRm.d.ts +3276 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +95 -0
- package/dist/collection-Bib61WiV.d.ts +294 -0
- package/dist/collection-CqtGPi4W.d.ts +39 -0
- package/dist/content-translation-zfUkE_OG.d.ts +8 -0
- package/dist/credential-6aOEGqMH.d.ts +30 -0
- package/dist/cron-DThzerR6.d.ts +9 -0
- package/dist/csv-upload--K35QedP.d.ts +8 -0
- package/dist/dashboard-XTe46250.d.ts +38 -0
- package/dist/dashboard-z9i1VUZC.d.ts +970 -0
- package/dist/data-action-rS27f2Ji.d.ts +95 -0
- package/dist/database-BLUMlywE.d.ts +997 -0
- package/dist/database-DqTespfa.d.ts +27 -0
- package/dist/dataset-C6lX1-cr.d.ts +4144 -0
- package/dist/dataset-Cj3XuKLe.d.ts +23 -0
- package/dist/dependency-D8Qs5Xdx.d.ts +827 -0
- package/dist/dependency-fN5_7a22.d.ts +299 -0
- package/dist/document-oZNDbDfx.d.ts +115 -0
- package/dist/domain/card.d.ts +2 -0
- package/dist/domain/card.js +140 -0
- package/dist/domain/collection.d.ts +2 -0
- package/dist/domain/collection.js +137 -0
- package/dist/domain/content-translation.d.ts +2 -0
- package/dist/domain/content-translation.js +5 -0
- package/dist/domain/cron.d.ts +2 -0
- package/dist/domain/cron.js +5 -0
- package/dist/domain/dashboard.d.ts +2 -0
- package/dist/domain/dashboard.js +194 -0
- package/dist/domain/data-action.d.ts +2 -0
- package/dist/domain/data-action.js +85 -0
- package/dist/domain/database.d.ts +2 -0
- package/dist/domain/database.js +56 -0
- package/dist/domain/dataset.d.ts +2 -0
- package/dist/domain/dataset.js +56 -0
- package/dist/domain/dependency.d.ts +2 -0
- package/dist/domain/dependency.js +165 -0
- package/dist/domain/document.d.ts +2 -0
- package/dist/domain/document.js +94 -0
- package/dist/domain/eid-translation.d.ts +2 -0
- package/dist/domain/eid-translation.js +36 -0
- package/dist/domain/embedding.d.ts +2 -0
- package/dist/domain/embedding.js +9 -0
- package/dist/domain/erd.d.ts +2 -0
- package/dist/domain/erd.js +45 -0
- package/dist/domain/field.d.ts +2 -0
- package/dist/domain/field.js +268 -0
- package/dist/domain/git-sync.d.ts +2 -0
- package/dist/domain/git-sync.js +147 -0
- package/dist/domain/glossary.d.ts +2 -0
- package/dist/domain/glossary.js +30 -0
- package/dist/domain/library.d.ts +2 -0
- package/dist/domain/library.js +83 -0
- package/dist/domain/measure.d.ts +2 -0
- package/dist/domain/measure.js +41 -0
- package/dist/domain/metric.d.ts +2 -0
- package/dist/domain/metric.js +139 -0
- package/dist/domain/moderation-review.d.ts +2 -0
- package/dist/domain/moderation-review.js +31 -0
- package/dist/domain/notification.d.ts +2 -0
- package/dist/domain/notification.js +138 -0
- package/dist/domain/parameter.d.ts +2 -0
- package/dist/domain/parameter.js +109 -0
- package/dist/domain/permission.d.ts +2 -0
- package/dist/domain/permission.js +36 -0
- package/dist/domain/pulse.d.ts +2 -0
- package/dist/domain/pulse.js +133 -0
- package/dist/domain/query.d.ts +2 -0
- package/dist/domain/query.js +13 -0
- package/dist/domain/replacement.d.ts +2 -0
- package/dist/domain/replacement.js +93 -0
- package/dist/domain/revision.d.ts +2 -0
- package/dist/domain/revision.js +63 -0
- package/dist/domain/search.d.ts +2 -0
- package/dist/domain/search.js +63 -0
- package/dist/domain/segment.d.ts +2 -0
- package/dist/domain/segment.js +44 -0
- package/dist/domain/session-properties.d.ts +2 -0
- package/dist/domain/session-properties.js +14 -0
- package/dist/domain/setting.d.ts +2 -0
- package/dist/domain/setting.js +22 -0
- package/dist/domain/setup.d.ts +2 -0
- package/dist/domain/setup.js +21 -0
- package/dist/domain/snippet.d.ts +2 -0
- package/dist/domain/snippet.js +38 -0
- package/dist/domain/table.d.ts +2 -0
- package/dist/domain/table.js +156 -0
- package/dist/domain/text.d.ts +5 -0
- package/dist/domain/text.js +6 -0
- package/dist/domain/timeline.d.ts +2 -0
- package/dist/domain/timeline.js +97 -0
- package/dist/domain/transform-dag-run.d.ts +2 -0
- package/dist/domain/transform-dag-run.js +19 -0
- package/dist/domain/transform-inspector.d.ts +2 -0
- package/dist/domain/transform-inspector.js +142 -0
- package/dist/domain/transform-job.d.ts +2 -0
- package/dist/domain/transform-job.js +109 -0
- package/dist/domain/transform-python.d.ts +2 -0
- package/dist/domain/transform-python.js +39 -0
- package/dist/domain/transform-tag.d.ts +2 -0
- package/dist/domain/transform-tag.js +17 -0
- package/dist/domain/transform-test.d.ts +2 -0
- package/dist/domain/transform-test.js +176 -0
- package/dist/domain/transform.d.ts +2 -0
- package/dist/domain/transform.js +235 -0
- package/dist/domain/upload.d.ts +2 -0
- package/dist/domain/upload.js +13 -0
- package/dist/domain/user.d.ts +2 -0
- package/dist/domain/user.js +16 -0
- package/dist/eid-translation-nuhr8St2.d.ts +143 -0
- package/dist/embedding-Cz3RUJYf.d.ts +10 -0
- package/dist/erd-BdeFEeSy.d.ts +842 -0
- package/dist/erd-BujD227Y.d.ts +51 -0
- package/dist/errors-DdMlaXqq.js +330 -0
- package/dist/errors.d.ts +2 -0
- package/dist/errors.js +189 -0
- package/dist/features-CnFkUCj2.d.ts +261 -0
- package/dist/field-BCRO19mk.d.ts +2547 -0
- package/dist/field-Bqn10Fq_.d.ts +50 -0
- package/dist/git-sync-DNXrNVCW.d.ts +258 -0
- package/dist/git-sync-gAMKsZgN.d.ts +205 -0
- package/dist/glossary-CHK3elPj.d.ts +35 -0
- package/dist/glossary-CqFlzW33.d.ts +15 -0
- package/dist/http/errors.d.ts +2 -0
- package/dist/http/errors.js +2 -0
- package/dist/http/oauth.d.ts +2 -0
- package/dist/http/oauth.js +201 -0
- package/dist/http/retry.d.ts +19 -0
- package/dist/http/retry.js +33 -0
- package/dist/http/transport.d.ts +2 -0
- package/dist/http/transport.js +2 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +62 -0
- package/dist/json-CZvjc3--.d.ts +19 -0
- package/dist/json-pointer.d.ts +4 -0
- package/dist/json-pointer.js +7 -0
- package/dist/json.d.ts +2 -0
- package/dist/json.js +44 -0
- package/dist/known-range-DTOBgTEC.d.ts +7 -0
- package/dist/library-Cx9h_RkU.d.ts +228 -0
- package/dist/list-BT_bBm9Z.d.ts +7 -0
- package/dist/list.d.ts +2 -0
- package/dist/list.js +1 -0
- package/dist/measure-CuMqPbQX.d.ts +108 -0
- package/dist/measure-KuXdjZYJ.d.ts +44 -0
- package/dist/metric-yvehaVCS.d.ts +2655 -0
- package/dist/moderation-review-B4RUTZ6_.d.ts +56 -0
- package/dist/network-error-5g4U1iul.js +62 -0
- package/dist/notification-BT2TDAd_.d.ts +379 -0
- package/dist/notification-BiegPoSD.d.ts +22 -0
- package/dist/oauth-C4ordeoJ.d.ts +59 -0
- package/dist/oauth-login-CJsT_3EE.d.ts +19 -0
- package/dist/oauth-login-D734Jvbq.js +179 -0
- package/dist/oauth-session-BlIlcd8Q.d.ts +6 -0
- package/dist/paginate-DZWvWvbm.d.ts +24 -0
- package/dist/paginate.d.ts +2 -0
- package/dist/paginate.js +49 -0
- package/dist/parameter-ak-J-IOj.d.ts +190 -0
- package/dist/permission-BnCQw5Kp.d.ts +149 -0
- package/dist/poll-CIwnee7h.d.ts +15 -0
- package/dist/poll.d.ts +2 -0
- package/dist/poll.js +47 -0
- package/dist/predicates.d.ts +10 -0
- package/dist/predicates.js +18 -0
- package/dist/pulse-CMc1Rwdj.d.ts +596 -0
- package/dist/pulse-dylocLd9.d.ts +18 -0
- package/dist/query-Xsin530u.d.ts +23 -0
- package/dist/refusal-B9aeHMc9.js +130 -0
- package/dist/replacement-CyvtbxGg.d.ts +2467 -0
- package/dist/replacement-S9U3gApY.d.ts +128 -0
- package/dist/requirement-check-CIA5IHC1.d.ts +17 -0
- package/dist/requirements-C0txASN8.d.ts +217 -0
- package/dist/resources/card.d.ts +2 -0
- package/dist/resources/card.js +103 -0
- package/dist/resources/collection.d.ts +2 -0
- package/dist/resources/collection.js +110 -0
- package/dist/resources/content-translation.d.ts +11 -0
- package/dist/resources/content-translation.js +27 -0
- package/dist/resources/csv-upload.d.ts +2 -0
- package/dist/resources/csv-upload.js +9 -0
- package/dist/resources/dashboard.d.ts +2 -0
- package/dist/resources/dashboard.js +218 -0
- package/dist/resources/data-action.d.ts +105 -0
- package/dist/resources/data-action.js +79 -0
- package/dist/resources/database.d.ts +2 -0
- package/dist/resources/database.js +103 -0
- package/dist/resources/dataset.d.ts +2 -0
- package/dist/resources/dataset.js +81 -0
- package/dist/resources/dependency.d.ts +2 -0
- package/dist/resources/dependency.js +150 -0
- package/dist/resources/document.d.ts +55 -0
- package/dist/resources/document.js +60 -0
- package/dist/resources/eid-translation.d.ts +8 -0
- package/dist/resources/eid-translation.js +19 -0
- package/dist/resources/erd.d.ts +2 -0
- package/dist/resources/erd.js +26 -0
- package/dist/resources/field.d.ts +2 -0
- package/dist/resources/field.js +98 -0
- package/dist/resources/git-sync.d.ts +2 -0
- package/dist/resources/git-sync.js +362 -0
- package/dist/resources/glossary.d.ts +2 -0
- package/dist/resources/glossary.js +51 -0
- package/dist/resources/library.d.ts +85 -0
- package/dist/resources/library.js +90 -0
- package/dist/resources/measure.d.ts +2 -0
- package/dist/resources/measure.js +57 -0
- package/dist/resources/metric.d.ts +2 -0
- package/dist/resources/metric.js +50 -0
- package/dist/resources/moderation-review.d.ts +23 -0
- package/dist/resources/moderation-review.js +24 -0
- package/dist/resources/notification.d.ts +2 -0
- package/dist/resources/notification.js +93 -0
- package/dist/resources/optional-parsed.d.ts +7 -0
- package/dist/resources/optional-parsed.js +14 -0
- package/dist/resources/permission.d.ts +10 -0
- package/dist/resources/permission.js +31 -0
- package/dist/resources/pivot-export.d.ts +10 -0
- package/dist/resources/pivot-export.js +16 -0
- package/dist/resources/pulse.d.ts +2 -0
- package/dist/resources/pulse.js +75 -0
- package/dist/resources/replacement.d.ts +2 -0
- package/dist/resources/replacement.js +82 -0
- package/dist/resources/request-body.d.ts +9 -0
- package/dist/resources/request-body.js +13 -0
- package/dist/resources/revision.d.ts +70 -0
- package/dist/resources/revision.js +51 -0
- package/dist/resources/search.d.ts +2 -0
- package/dist/resources/search.js +57 -0
- package/dist/resources/segment.d.ts +2 -0
- package/dist/resources/segment.js +55 -0
- package/dist/resources/setting.d.ts +11 -0
- package/dist/resources/setting.js +43 -0
- package/dist/resources/setup.d.ts +8 -0
- package/dist/resources/setup.js +18 -0
- package/dist/resources/snippet.d.ts +2 -0
- package/dist/resources/snippet.js +52 -0
- package/dist/resources/table.d.ts +2 -0
- package/dist/resources/table.js +275 -0
- package/dist/resources/timeline-event.d.ts +12 -0
- package/dist/resources/timeline-event.js +51 -0
- package/dist/resources/timeline.d.ts +2 -0
- package/dist/resources/timeline.js +82 -0
- package/dist/resources/transform-dag-run.d.ts +22 -0
- package/dist/resources/transform-dag-run.js +32 -0
- package/dist/resources/transform-inspector.d.ts +214 -0
- package/dist/resources/transform-inspector.js +47 -0
- package/dist/resources/transform-job.d.ts +2 -0
- package/dist/resources/transform-job.js +90 -0
- package/dist/resources/transform-python.d.ts +52 -0
- package/dist/resources/transform-python.js +56 -0
- package/dist/resources/transform-tag.d.ts +35 -0
- package/dist/resources/transform-tag.js +47 -0
- package/dist/resources/transform-test.d.ts +2 -0
- package/dist/resources/transform-test.js +75 -0
- package/dist/resources/transform.d.ts +2 -0
- package/dist/resources/transform.js +217 -0
- package/dist/resources/upload.d.ts +2 -0
- package/dist/resources/upload.js +48 -0
- package/dist/resources/user.d.ts +8 -0
- package/dist/resources/user.js +11 -0
- package/dist/revision-CQBPhohA.d.ts +104 -0
- package/dist/search-BxJipLN6.d.ts +26 -0
- package/dist/search-NZR6iRBs.d.ts +92 -0
- package/dist/segment-D2i34X9l.d.ts +16 -0
- package/dist/segment-pj3wklGe.d.ts +47 -0
- package/dist/session-properties-COtlxAcK.d.ts +15 -0
- package/dist/setting-DXuQGXGF.d.ts +25 -0
- package/dist/setup-Ez_U7GmM.d.ts +26 -0
- package/dist/signal.d.ts +8 -0
- package/dist/signal.js +25 -0
- package/dist/snippet-RnnWa4TL.d.ts +16 -0
- package/dist/snippet-hEV429Pv.d.ts +41 -0
- package/dist/table-B3-UaPHa.d.ts +3229 -0
- package/dist/table-B_lfuaHc.d.ts +176 -0
- package/dist/tag-qzjGGci8.d.ts +48 -0
- package/dist/timeline-C2IEcRlP.d.ts +21 -0
- package/dist/timeline-folD3mQ_.d.ts +218 -0
- package/dist/transform-CDurgE1D.d.ts +443 -0
- package/dist/transform-CXOT5kFe.d.ts +638 -0
- package/dist/transform-dag-run-BgZwv1yx.d.ts +49 -0
- package/dist/transform-inspector-BUYBt6--.d.ts +374 -0
- package/dist/transform-job-29P6BULe.d.ts +237 -0
- package/dist/transform-job-CTJImaOd.d.ts +96 -0
- package/dist/transform-python-DdDnW6yK.d.ts +56 -0
- package/dist/transform-tag-DVUIZTEM.d.ts +25 -0
- package/dist/transform-test-A-CJYT6B.d.ts +412 -0
- package/dist/transform-test-BwuyrHpT.d.ts +346 -0
- package/dist/transport-E0ZaPNWJ.d.ts +462 -0
- package/dist/transport-HP7cyo9N.js +397 -0
- package/dist/upload-B7PG3ePk.d.ts +12 -0
- package/dist/upload-UPfZFdbH.d.ts +22 -0
- package/dist/url-CI0pxHOc.d.ts +7 -0
- package/dist/url.d.ts +2 -0
- package/dist/url.js +34 -0
- package/dist/user-2r0OBoO6.d.ts +18 -0
- package/dist/version/capability-error.d.ts +2 -0
- package/dist/version/capability-error.js +42 -0
- package/dist/version/features.d.ts +2 -0
- package/dist/version/features.js +143 -0
- package/dist/version/known-range.d.ts +2 -0
- package/dist/version/known-range.js +7 -0
- package/dist/version/probe.d.ts +2 -0
- package/dist/version/probe.js +30 -0
- package/dist/version/profile.d.ts +2 -0
- package/dist/version/profile.js +64 -0
- package/dist/version/requirement-check.d.ts +2 -0
- package/dist/version/requirement-check.js +62 -0
- package/dist/version/requirements.d.ts +2 -0
- package/dist/version/requirements.js +219 -0
- package/dist/version/tag.d.ts +2 -0
- package/dist/version/tag.js +52 -0
- package/package.json +65 -4
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { ConfigError } from "./errors.js";
|
|
2
|
+
import { oauthCredentialFromTokens } from "./auth/credential.js";
|
|
3
|
+
import { OAUTH_SCOPE, discoverLoginMetadata, exchangeCode, registerClient } from "./http/oauth.js";
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
6
|
+
//#region src/auth/callback-server.ts
|
|
7
|
+
const LOOPBACK_HOST = "127.0.0.1";
|
|
8
|
+
const CALLBACK_PATH = "/callback";
|
|
9
|
+
const DEFAULT_TIMEOUT_MS = 3e5;
|
|
10
|
+
function parseCallbackQuery(rawUrl) {
|
|
11
|
+
const queryStart = rawUrl.indexOf("?");
|
|
12
|
+
const params = new URLSearchParams(queryStart === -1 ? "" : rawUrl.slice(queryStart + 1));
|
|
13
|
+
return {
|
|
14
|
+
code: params.get("code"),
|
|
15
|
+
state: params.get("state"),
|
|
16
|
+
error: params.get("error"),
|
|
17
|
+
errorDescription: params.get("error_description")
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function isCallbackPath(rawUrl) {
|
|
21
|
+
const queryStart = rawUrl.indexOf("?");
|
|
22
|
+
return (queryStart === -1 ? rawUrl : rawUrl.slice(0, queryStart)) === CALLBACK_PATH;
|
|
23
|
+
}
|
|
24
|
+
function escapeHtml(value) {
|
|
25
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
26
|
+
}
|
|
27
|
+
function htmlPage(title, message) {
|
|
28
|
+
return "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><title>" + escapeHtml(title) + "</title></head><body style=\"font-family:system-ui;text-align:center;padding-top:4rem;color:#4c5773\"><h1>" + escapeHtml(title) + "</h1><p>" + escapeHtml(message) + "</p><p>You can close this tab and return to your terminal.</p></body></html>";
|
|
29
|
+
}
|
|
30
|
+
function respond(res, status, title, message) {
|
|
31
|
+
res.writeHead(status, {
|
|
32
|
+
"content-type": "text/html; charset=utf-8",
|
|
33
|
+
connection: "close"
|
|
34
|
+
});
|
|
35
|
+
res.end(htmlPage(title, message));
|
|
36
|
+
}
|
|
37
|
+
function serverPort(server) {
|
|
38
|
+
const address = server.address();
|
|
39
|
+
if (address === null || typeof address === "string") throw new ConfigError("could not determine loopback callback port");
|
|
40
|
+
return address.port;
|
|
41
|
+
}
|
|
42
|
+
function startCallbackServer(expectedState, timeoutMs = DEFAULT_TIMEOUT_MS) {
|
|
43
|
+
return new Promise((resolveServer, rejectServer) => {
|
|
44
|
+
let settle = null;
|
|
45
|
+
let fail = null;
|
|
46
|
+
let outcome = null;
|
|
47
|
+
const server = createServer((req, res) => {
|
|
48
|
+
const rawUrl = req.url ?? "";
|
|
49
|
+
if (!isCallbackPath(rawUrl)) {
|
|
50
|
+
respond(res, 404, "Not found", "Unexpected request.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const query = parseCallbackQuery(rawUrl);
|
|
54
|
+
if (query.state !== expectedState) {
|
|
55
|
+
respond(res, 400, "Login failed", "Invalid or missing state.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (query.error !== null) {
|
|
59
|
+
const detail = query.errorDescription ?? query.error;
|
|
60
|
+
respond(res, 400, "Login failed", detail);
|
|
61
|
+
deliver(new ConfigError(`authorization denied: ${detail}`));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (query.code === null) {
|
|
65
|
+
respond(res, 400, "Login failed", "Missing authorization code.");
|
|
66
|
+
deliver(new ConfigError("authorization callback missing code"));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
respond(res, 200, "Login complete", "Authorization complete. You can close this window.");
|
|
70
|
+
deliver({
|
|
71
|
+
code: query.code,
|
|
72
|
+
state: query.state
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
function deliver(result) {
|
|
76
|
+
if (outcome !== null) return;
|
|
77
|
+
outcome = result;
|
|
78
|
+
if (result instanceof Error) fail?.(result);
|
|
79
|
+
else settle?.(result);
|
|
80
|
+
}
|
|
81
|
+
const timer = setTimeout(() => {
|
|
82
|
+
deliver(new ConfigError(`timed out waiting for browser login after ${timeoutMs}ms`));
|
|
83
|
+
}, timeoutMs);
|
|
84
|
+
timer.unref();
|
|
85
|
+
server.on("error", (error) => {
|
|
86
|
+
rejectServer(error);
|
|
87
|
+
deliver(error);
|
|
88
|
+
});
|
|
89
|
+
server.listen(0, LOOPBACK_HOST, () => {
|
|
90
|
+
const port = serverPort(server);
|
|
91
|
+
resolveServer({
|
|
92
|
+
redirectUri: `http://${LOOPBACK_HOST}:${port}${CALLBACK_PATH}`,
|
|
93
|
+
waitForCallback() {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
if (outcome !== null) {
|
|
96
|
+
if (outcome instanceof Error) reject(outcome);
|
|
97
|
+
else resolve(outcome);
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
settle = resolve;
|
|
101
|
+
fail = reject;
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
close() {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
server.close();
|
|
107
|
+
server.closeAllConnections();
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/auth/pkce.ts
|
|
115
|
+
const VERIFIER_BYTES = 32;
|
|
116
|
+
const STATE_BYTES = 16;
|
|
117
|
+
function base64Url(buffer) {
|
|
118
|
+
return buffer.toString("base64url");
|
|
119
|
+
}
|
|
120
|
+
function generatePkce() {
|
|
121
|
+
const verifier = base64Url(randomBytes(VERIFIER_BYTES));
|
|
122
|
+
return {
|
|
123
|
+
verifier,
|
|
124
|
+
challenge: base64Url(createHash("sha256").update(verifier).digest())
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function randomState() {
|
|
128
|
+
return base64Url(randomBytes(STATE_BYTES));
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
//#region src/auth/oauth-login.ts
|
|
132
|
+
function buildAuthorizeUrl(authorizationEndpoint, params) {
|
|
133
|
+
return `${authorizationEndpoint}${authorizationEndpoint.includes("?") ? "&" : "?"}${new URLSearchParams(params).toString()}`;
|
|
134
|
+
}
|
|
135
|
+
async function resolveClientId(input, registrationEndpoint, redirectUri) {
|
|
136
|
+
if (input.clientId !== void 0) return input.clientId;
|
|
137
|
+
if (registrationEndpoint === void 0) throw new ConfigError("this Metabase has dynamic client registration disabled; pass clientId with a pre-registered native client");
|
|
138
|
+
return (await registerClient({
|
|
139
|
+
registrationEndpoint,
|
|
140
|
+
redirectUri,
|
|
141
|
+
clientName: input.clientName,
|
|
142
|
+
userAgent: input.userAgent
|
|
143
|
+
})).client_id;
|
|
144
|
+
}
|
|
145
|
+
async function oauthLogin(input, deps) {
|
|
146
|
+
const metadata = input.metadata ?? await discoverLoginMetadata(input.baseUrl, input.userAgent);
|
|
147
|
+
const pkce = generatePkce();
|
|
148
|
+
const state = randomState();
|
|
149
|
+
const server = await startCallbackServer(state, input.timeoutMs);
|
|
150
|
+
try {
|
|
151
|
+
const clientId = await resolveClientId(input, metadata.registration_endpoint, server.redirectUri);
|
|
152
|
+
const authorizeUrl = buildAuthorizeUrl(metadata.authorization_endpoint, {
|
|
153
|
+
response_type: "code",
|
|
154
|
+
client_id: clientId,
|
|
155
|
+
redirect_uri: server.redirectUri,
|
|
156
|
+
code_challenge: pkce.challenge,
|
|
157
|
+
code_challenge_method: "S256",
|
|
158
|
+
state,
|
|
159
|
+
scope: OAUTH_SCOPE
|
|
160
|
+
});
|
|
161
|
+
const opened = await deps.openBrowser(authorizeUrl);
|
|
162
|
+
deps.onAuthorizeUrl(authorizeUrl, opened);
|
|
163
|
+
const callback = await server.waitForCallback();
|
|
164
|
+
const tokens = await exchangeCode({
|
|
165
|
+
tokenEndpoint: metadata.token_endpoint,
|
|
166
|
+
code: callback.code,
|
|
167
|
+
redirectUri: server.redirectUri,
|
|
168
|
+
clientId,
|
|
169
|
+
codeVerifier: pkce.verifier,
|
|
170
|
+
userAgent: input.userAgent
|
|
171
|
+
});
|
|
172
|
+
if (tokens.refresh_token === void 0) throw new ConfigError("token endpoint did not return a refresh token");
|
|
173
|
+
return oauthCredentialFromTokens(tokens, tokens.refresh_token, clientId, deps.now());
|
|
174
|
+
} finally {
|
|
175
|
+
server.close();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
//#endregion
|
|
179
|
+
export { oauthLogin as t };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { c as OAuthCredential } from "./credential-6aOEGqMH.js";
|
|
2
|
+
//#region src/auth/oauth-session.d.ts
|
|
3
|
+
declare function refreshOAuthCredential(baseUrl: string, credential: OAuthCredential, nowMs: number, userAgent: string): Promise<OAuthCredential>;
|
|
4
|
+
declare function revokeOAuthCredential(baseUrl: string, credential: OAuthCredential, userAgent: string): Promise<boolean>;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { revokeOAuthCredential as n, refreshOAuthCredential as t };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { d as QueryValue, h as Transport } from "./transport-E0ZaPNWJ.js";
|
|
2
|
+
import { ZodType } from "zod";
|
|
3
|
+
//#region src/paginate.d.ts
|
|
4
|
+
declare const DEFAULT_PAGE_SIZE = 50;
|
|
5
|
+
interface PaginateOptions {
|
|
6
|
+
query?: Record<string, QueryValue>;
|
|
7
|
+
pageSize?: number;
|
|
8
|
+
offset?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
interface Page<T> {
|
|
13
|
+
items: T[];
|
|
14
|
+
total: number | null;
|
|
15
|
+
}
|
|
16
|
+
interface PaginatedEnvelope<T> {
|
|
17
|
+
data: T[];
|
|
18
|
+
total?: number | null | undefined;
|
|
19
|
+
limit?: number | undefined;
|
|
20
|
+
offset?: number | undefined;
|
|
21
|
+
}
|
|
22
|
+
declare function paginatePages<T>(client: Transport, path: string, itemSchema: ZodType<T>, opts?: PaginateOptions): AsyncIterable<Page<T>>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { paginatePages as a, PaginatedEnvelope as i, Page as n, PaginateOptions as r, DEFAULT_PAGE_SIZE as t };
|
package/dist/paginate.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ConfigError, InternalError } from "./errors.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
//#region src/paginate.ts
|
|
4
|
+
const DEFAULT_PAGE_SIZE = 50;
|
|
5
|
+
async function* paginatePages(client, path, itemSchema, opts = {}) {
|
|
6
|
+
const envelopeSchema = paginatedEnvelopeSchema(itemSchema);
|
|
7
|
+
const pageSize = opts.pageSize ?? 50;
|
|
8
|
+
if (!Number.isInteger(pageSize) || pageSize < 1) throw new InternalError(`pageSize must be an integer of at least 1, got ${pageSize}`);
|
|
9
|
+
const start = opts.offset ?? 0;
|
|
10
|
+
const max = opts.max ?? Number.POSITIVE_INFINITY;
|
|
11
|
+
let taken = 0;
|
|
12
|
+
let previousHead = null;
|
|
13
|
+
while (taken < max) {
|
|
14
|
+
const remaining = max - taken;
|
|
15
|
+
const limit = Math.min(pageSize, remaining);
|
|
16
|
+
const offset = start + taken;
|
|
17
|
+
const envelope = await client.requestParsed(envelopeSchema, path, {
|
|
18
|
+
query: {
|
|
19
|
+
...opts.query,
|
|
20
|
+
limit,
|
|
21
|
+
offset
|
|
22
|
+
},
|
|
23
|
+
...opts.signal !== void 0 && { signal: opts.signal }
|
|
24
|
+
});
|
|
25
|
+
const items = envelope.data.length > remaining ? envelope.data.slice(0, remaining) : envelope.data;
|
|
26
|
+
const total = envelope.total ?? null;
|
|
27
|
+
const head = items.length === 0 ? null : JSON.stringify(items[0]);
|
|
28
|
+
if (head !== null && head === previousHead) throw new ConfigError(`the endpoint returned the same first row at offset ${offset} as at the previous offset; it is ignoring the offset parameter, so paging cannot advance`);
|
|
29
|
+
previousHead = head;
|
|
30
|
+
yield {
|
|
31
|
+
items,
|
|
32
|
+
total
|
|
33
|
+
};
|
|
34
|
+
if (items.length === 0) return;
|
|
35
|
+
const consumed = taken + items.length;
|
|
36
|
+
if (total !== null && start + consumed === total) return;
|
|
37
|
+
taken = consumed;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function paginatedEnvelopeSchema(itemSchema) {
|
|
41
|
+
return z.object({
|
|
42
|
+
data: z.array(itemSchema),
|
|
43
|
+
total: z.number().int().nonnegative().nullable().optional(),
|
|
44
|
+
limit: z.number().int().nonnegative().optional(),
|
|
45
|
+
offset: z.number().int().nonnegative().optional()
|
|
46
|
+
}).loose();
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { DEFAULT_PAGE_SIZE, paginatePages };
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/domain/parameter.d.ts
|
|
3
|
+
declare const ParameterType: z.ZodEnum<{
|
|
4
|
+
number: "number";
|
|
5
|
+
boolean: "boolean";
|
|
6
|
+
id: "id";
|
|
7
|
+
date: "date";
|
|
8
|
+
text: "text";
|
|
9
|
+
"temporal-unit": "temporal-unit";
|
|
10
|
+
"date/single": "date/single";
|
|
11
|
+
category: "category";
|
|
12
|
+
"location/city": "location/city";
|
|
13
|
+
"location/state": "location/state";
|
|
14
|
+
"location/zip_code": "location/zip_code";
|
|
15
|
+
"location/country": "location/country";
|
|
16
|
+
"date/range": "date/range";
|
|
17
|
+
"date/month-year": "date/month-year";
|
|
18
|
+
"date/quarter-year": "date/quarter-year";
|
|
19
|
+
"date/relative": "date/relative";
|
|
20
|
+
"date/all-options": "date/all-options";
|
|
21
|
+
"number/!=": "number/!=";
|
|
22
|
+
"number/<=": "number/<=";
|
|
23
|
+
"number/=": "number/=";
|
|
24
|
+
"number/>=": "number/>=";
|
|
25
|
+
"number/between": "number/between";
|
|
26
|
+
"string/!=": "string/!=";
|
|
27
|
+
"string/=": "string/=";
|
|
28
|
+
"string/contains": "string/contains";
|
|
29
|
+
"string/does-not-contain": "string/does-not-contain";
|
|
30
|
+
"string/ends-with": "string/ends-with";
|
|
31
|
+
"string/starts-with": "string/starts-with";
|
|
32
|
+
"boolean/=": "boolean/=";
|
|
33
|
+
}>;
|
|
34
|
+
type ParameterType = z.infer<typeof ParameterType>;
|
|
35
|
+
declare const TemporalUnit: z.ZodEnum<{
|
|
36
|
+
default: "default";
|
|
37
|
+
millisecond: "millisecond";
|
|
38
|
+
second: "second";
|
|
39
|
+
minute: "minute";
|
|
40
|
+
hour: "hour";
|
|
41
|
+
day: "day";
|
|
42
|
+
week: "week";
|
|
43
|
+
month: "month";
|
|
44
|
+
quarter: "quarter";
|
|
45
|
+
year: "year";
|
|
46
|
+
"second-of-minute": "second-of-minute";
|
|
47
|
+
"minute-of-hour": "minute-of-hour";
|
|
48
|
+
"hour-of-day": "hour-of-day";
|
|
49
|
+
"day-of-week": "day-of-week";
|
|
50
|
+
"day-of-month": "day-of-month";
|
|
51
|
+
"day-of-year": "day-of-year";
|
|
52
|
+
"week-of-year": "week-of-year";
|
|
53
|
+
"month-of-year": "month-of-year";
|
|
54
|
+
"quarter-of-year": "quarter-of-year";
|
|
55
|
+
"year-of-era": "year-of-era";
|
|
56
|
+
}>;
|
|
57
|
+
type TemporalUnit = z.infer<typeof TemporalUnit>;
|
|
58
|
+
declare const ValuesSourceType: z.ZodEnum<{
|
|
59
|
+
card: "card";
|
|
60
|
+
"static-list": "static-list";
|
|
61
|
+
}>;
|
|
62
|
+
type ValuesSourceType = z.infer<typeof ValuesSourceType>;
|
|
63
|
+
declare const ValuesQueryType: z.ZodEnum<{
|
|
64
|
+
list: "list";
|
|
65
|
+
search: "search";
|
|
66
|
+
none: "none";
|
|
67
|
+
}>;
|
|
68
|
+
type ValuesQueryType = z.infer<typeof ValuesQueryType>;
|
|
69
|
+
declare const ParameterTemplateTagRef: z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
70
|
+
id: z.ZodString;
|
|
71
|
+
}, z.core.$loose>]>], null>;
|
|
72
|
+
declare const ParameterTextTagTarget: z.ZodTuple<[z.ZodLiteral<"text-tag">, z.ZodString], null>;
|
|
73
|
+
declare const ParameterTarget: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"dimension">, z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
}, z.core.$loose>]>], null>, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>], z.ZodUnknown>, z.ZodTuple<[z.ZodLiteral<"variable">, z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
}, z.core.$loose>]>], null>, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>], null>, z.ZodTuple<[z.ZodLiteral<"text-tag">, z.ZodString], null>, z.ZodNumber, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>;
|
|
78
|
+
type ParameterTarget = z.infer<typeof ParameterTarget>;
|
|
79
|
+
declare const ValuesSourceConfig: z.ZodObject<{
|
|
80
|
+
values: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
81
|
+
card_id: z.ZodOptional<z.ZodNumber>;
|
|
82
|
+
value_field: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodUnknown>>;
|
|
83
|
+
label_field: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodUnknown>>;
|
|
84
|
+
}, z.core.$loose>;
|
|
85
|
+
type ValuesSourceConfig = z.infer<typeof ValuesSourceConfig>;
|
|
86
|
+
declare const Parameter: z.ZodObject<{
|
|
87
|
+
id: z.ZodString;
|
|
88
|
+
type: z.ZodEnum<{
|
|
89
|
+
number: "number";
|
|
90
|
+
boolean: "boolean";
|
|
91
|
+
id: "id";
|
|
92
|
+
date: "date";
|
|
93
|
+
text: "text";
|
|
94
|
+
"temporal-unit": "temporal-unit";
|
|
95
|
+
"date/single": "date/single";
|
|
96
|
+
category: "category";
|
|
97
|
+
"location/city": "location/city";
|
|
98
|
+
"location/state": "location/state";
|
|
99
|
+
"location/zip_code": "location/zip_code";
|
|
100
|
+
"location/country": "location/country";
|
|
101
|
+
"date/range": "date/range";
|
|
102
|
+
"date/month-year": "date/month-year";
|
|
103
|
+
"date/quarter-year": "date/quarter-year";
|
|
104
|
+
"date/relative": "date/relative";
|
|
105
|
+
"date/all-options": "date/all-options";
|
|
106
|
+
"number/!=": "number/!=";
|
|
107
|
+
"number/<=": "number/<=";
|
|
108
|
+
"number/=": "number/=";
|
|
109
|
+
"number/>=": "number/>=";
|
|
110
|
+
"number/between": "number/between";
|
|
111
|
+
"string/!=": "string/!=";
|
|
112
|
+
"string/=": "string/=";
|
|
113
|
+
"string/contains": "string/contains";
|
|
114
|
+
"string/does-not-contain": "string/does-not-contain";
|
|
115
|
+
"string/ends-with": "string/ends-with";
|
|
116
|
+
"string/starts-with": "string/starts-with";
|
|
117
|
+
"boolean/=": "boolean/=";
|
|
118
|
+
}>;
|
|
119
|
+
name: z.ZodOptional<z.ZodString>;
|
|
120
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
121
|
+
sectionId: z.ZodOptional<z.ZodString>;
|
|
122
|
+
default: z.ZodOptional<z.ZodUnknown>;
|
|
123
|
+
required: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
|
|
124
|
+
filteringParameters: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodString>>>;
|
|
125
|
+
target: z.ZodOptional<z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"dimension">, z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
126
|
+
id: z.ZodString;
|
|
127
|
+
}, z.core.$loose>]>], null>, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>], z.ZodUnknown>, z.ZodTuple<[z.ZodLiteral<"variable">, z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
128
|
+
id: z.ZodString;
|
|
129
|
+
}, z.core.$loose>]>], null>, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>], null>, z.ZodTuple<[z.ZodLiteral<"text-tag">, z.ZodString], null>, z.ZodNumber, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>>;
|
|
130
|
+
temporal_units: z.ZodOptional<z.ZodNullable<z.ZodArray<z.ZodEnum<{
|
|
131
|
+
default: "default";
|
|
132
|
+
millisecond: "millisecond";
|
|
133
|
+
second: "second";
|
|
134
|
+
minute: "minute";
|
|
135
|
+
hour: "hour";
|
|
136
|
+
day: "day";
|
|
137
|
+
week: "week";
|
|
138
|
+
month: "month";
|
|
139
|
+
quarter: "quarter";
|
|
140
|
+
year: "year";
|
|
141
|
+
"second-of-minute": "second-of-minute";
|
|
142
|
+
"minute-of-hour": "minute-of-hour";
|
|
143
|
+
"hour-of-day": "hour-of-day";
|
|
144
|
+
"day-of-week": "day-of-week";
|
|
145
|
+
"day-of-month": "day-of-month";
|
|
146
|
+
"day-of-year": "day-of-year";
|
|
147
|
+
"week-of-year": "week-of-year";
|
|
148
|
+
"month-of-year": "month-of-year";
|
|
149
|
+
"quarter-of-year": "quarter-of-year";
|
|
150
|
+
"year-of-era": "year-of-era";
|
|
151
|
+
}>>>>;
|
|
152
|
+
values_query_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
153
|
+
list: "list";
|
|
154
|
+
search: "search";
|
|
155
|
+
none: "none";
|
|
156
|
+
}>>>;
|
|
157
|
+
values_source_type: z.ZodOptional<z.ZodNullable<z.ZodEnum<{
|
|
158
|
+
card: "card";
|
|
159
|
+
"static-list": "static-list";
|
|
160
|
+
}>>>;
|
|
161
|
+
values_source_config: z.ZodOptional<z.ZodNullable<z.ZodObject<{
|
|
162
|
+
values: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
163
|
+
card_id: z.ZodOptional<z.ZodNumber>;
|
|
164
|
+
value_field: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodUnknown>>;
|
|
165
|
+
label_field: z.ZodOptional<z.ZodTuple<[z.ZodString], z.ZodUnknown>>;
|
|
166
|
+
}, z.core.$loose>>>;
|
|
167
|
+
}, z.core.$loose>;
|
|
168
|
+
type Parameter = z.infer<typeof Parameter>;
|
|
169
|
+
declare const ParameterMapping: z.ZodObject<{
|
|
170
|
+
parameter_id: z.ZodString;
|
|
171
|
+
target: z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"dimension">, z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
172
|
+
id: z.ZodString;
|
|
173
|
+
}, z.core.$loose>]>], null>, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>], z.ZodUnknown>, z.ZodTuple<[z.ZodLiteral<"variable">, z.ZodUnion<readonly [z.ZodTuple<[z.ZodLiteral<"template-tag">, z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
174
|
+
id: z.ZodString;
|
|
175
|
+
}, z.core.$loose>]>], null>, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>], null>, z.ZodTuple<[z.ZodLiteral<"text-tag">, z.ZodString], null>, z.ZodNumber, z.ZodTuple<[z.ZodString], z.ZodUnknown>]>;
|
|
176
|
+
card_id: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
|
|
177
|
+
}, z.core.$loose>;
|
|
178
|
+
type ParameterMapping = z.infer<typeof ParameterMapping>;
|
|
179
|
+
declare const ParameterValues: z.ZodObject<{
|
|
180
|
+
values: z.ZodArray<z.ZodArray<z.ZodUnknown>>;
|
|
181
|
+
has_more_values: z.ZodBoolean;
|
|
182
|
+
}, z.core.$loose>;
|
|
183
|
+
type ParameterValues = z.infer<typeof ParameterValues>;
|
|
184
|
+
declare const ParameterValuesCompact: z.ZodObject<{
|
|
185
|
+
values: z.ZodArray<z.ZodArray<z.ZodUnknown>>;
|
|
186
|
+
has_more_values: z.ZodBoolean;
|
|
187
|
+
}, z.core.$strip>;
|
|
188
|
+
type ParameterValuesCompact = z.infer<typeof ParameterValuesCompact>;
|
|
189
|
+
//#endregion
|
|
190
|
+
export { ParameterTextTagTarget as a, ParameterValuesCompact as c, ValuesSourceConfig as d, ValuesSourceType as f, ParameterTemplateTagRef as i, TemporalUnit as l, ParameterMapping as n, ParameterType as o, ParameterTarget as r, ParameterValues as s, Parameter as t, ValuesQueryType as u };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region src/domain/permission.d.ts
|
|
3
|
+
declare const ViewDataPermission: z.ZodEnum<{
|
|
4
|
+
unrestricted: "unrestricted";
|
|
5
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
6
|
+
blocked: "blocked";
|
|
7
|
+
sandboxed: "sandboxed";
|
|
8
|
+
impersonated: "impersonated";
|
|
9
|
+
}>;
|
|
10
|
+
type ViewDataPermission = z.infer<typeof ViewDataPermission>;
|
|
11
|
+
declare const CreateQueriesPermission: z.ZodEnum<{
|
|
12
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
13
|
+
"query-builder": "query-builder";
|
|
14
|
+
no: "no";
|
|
15
|
+
}>;
|
|
16
|
+
type CreateQueriesPermission = z.infer<typeof CreateQueriesPermission>;
|
|
17
|
+
declare const DownloadPermission: z.ZodEnum<{
|
|
18
|
+
full: "full";
|
|
19
|
+
limited: "limited";
|
|
20
|
+
}>;
|
|
21
|
+
type DownloadPermission = z.infer<typeof DownloadPermission>;
|
|
22
|
+
declare const DataModelPermission: z.ZodLiteral<"all">;
|
|
23
|
+
type DataModelPermission = z.infer<typeof DataModelPermission>;
|
|
24
|
+
declare const YesNoPermission: z.ZodEnum<{
|
|
25
|
+
no: "no";
|
|
26
|
+
yes: "yes";
|
|
27
|
+
}>;
|
|
28
|
+
type YesNoPermission = z.infer<typeof YesNoPermission>;
|
|
29
|
+
declare const DatabasePermissions: z.ZodObject<{
|
|
30
|
+
"view-data": z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
31
|
+
unrestricted: "unrestricted";
|
|
32
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
33
|
+
blocked: "blocked";
|
|
34
|
+
sandboxed: "sandboxed";
|
|
35
|
+
impersonated: "impersonated";
|
|
36
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
37
|
+
unrestricted: "unrestricted";
|
|
38
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
39
|
+
blocked: "blocked";
|
|
40
|
+
sandboxed: "sandboxed";
|
|
41
|
+
impersonated: "impersonated";
|
|
42
|
+
}>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
43
|
+
unrestricted: "unrestricted";
|
|
44
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
45
|
+
blocked: "blocked";
|
|
46
|
+
sandboxed: "sandboxed";
|
|
47
|
+
impersonated: "impersonated";
|
|
48
|
+
}>>]>>]>>;
|
|
49
|
+
"create-queries": z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
50
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
51
|
+
"query-builder": "query-builder";
|
|
52
|
+
no: "no";
|
|
53
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
54
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
55
|
+
"query-builder": "query-builder";
|
|
56
|
+
no: "no";
|
|
57
|
+
}>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
58
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
59
|
+
"query-builder": "query-builder";
|
|
60
|
+
no: "no";
|
|
61
|
+
}>>]>>]>>;
|
|
62
|
+
download: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
schemas: z.ZodUnion<readonly [z.ZodEnum<{
|
|
64
|
+
full: "full";
|
|
65
|
+
limited: "limited";
|
|
66
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
67
|
+
full: "full";
|
|
68
|
+
limited: "limited";
|
|
69
|
+
}>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
70
|
+
full: "full";
|
|
71
|
+
limited: "limited";
|
|
72
|
+
}>>]>>]>;
|
|
73
|
+
}, z.core.$loose>>;
|
|
74
|
+
"data-model": z.ZodOptional<z.ZodObject<{
|
|
75
|
+
schemas: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodRecord<z.ZodString, z.ZodLiteral<"all">>]>>]>;
|
|
76
|
+
}, z.core.$loose>>;
|
|
77
|
+
details: z.ZodOptional<z.ZodEnum<{
|
|
78
|
+
no: "no";
|
|
79
|
+
yes: "yes";
|
|
80
|
+
}>>;
|
|
81
|
+
transforms: z.ZodOptional<z.ZodEnum<{
|
|
82
|
+
no: "no";
|
|
83
|
+
yes: "yes";
|
|
84
|
+
}>>;
|
|
85
|
+
}, z.core.$loose>;
|
|
86
|
+
type DatabasePermissions = z.infer<typeof DatabasePermissions>;
|
|
87
|
+
declare const PermissionsGraph: z.ZodObject<{
|
|
88
|
+
revision: z.ZodNumber;
|
|
89
|
+
groups: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
90
|
+
"view-data": z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
91
|
+
unrestricted: "unrestricted";
|
|
92
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
93
|
+
blocked: "blocked";
|
|
94
|
+
sandboxed: "sandboxed";
|
|
95
|
+
impersonated: "impersonated";
|
|
96
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
97
|
+
unrestricted: "unrestricted";
|
|
98
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
99
|
+
blocked: "blocked";
|
|
100
|
+
sandboxed: "sandboxed";
|
|
101
|
+
impersonated: "impersonated";
|
|
102
|
+
}>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
103
|
+
unrestricted: "unrestricted";
|
|
104
|
+
"legacy-no-self-service": "legacy-no-self-service";
|
|
105
|
+
blocked: "blocked";
|
|
106
|
+
sandboxed: "sandboxed";
|
|
107
|
+
impersonated: "impersonated";
|
|
108
|
+
}>>]>>]>>;
|
|
109
|
+
"create-queries": z.ZodOptional<z.ZodUnion<readonly [z.ZodEnum<{
|
|
110
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
111
|
+
"query-builder": "query-builder";
|
|
112
|
+
no: "no";
|
|
113
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
114
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
115
|
+
"query-builder": "query-builder";
|
|
116
|
+
no: "no";
|
|
117
|
+
}>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
118
|
+
"query-builder-and-native": "query-builder-and-native";
|
|
119
|
+
"query-builder": "query-builder";
|
|
120
|
+
no: "no";
|
|
121
|
+
}>>]>>]>>;
|
|
122
|
+
download: z.ZodOptional<z.ZodObject<{
|
|
123
|
+
schemas: z.ZodUnion<readonly [z.ZodEnum<{
|
|
124
|
+
full: "full";
|
|
125
|
+
limited: "limited";
|
|
126
|
+
}>, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodEnum<{
|
|
127
|
+
full: "full";
|
|
128
|
+
limited: "limited";
|
|
129
|
+
}>, z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
130
|
+
full: "full";
|
|
131
|
+
limited: "limited";
|
|
132
|
+
}>>]>>]>;
|
|
133
|
+
}, z.core.$loose>>;
|
|
134
|
+
"data-model": z.ZodOptional<z.ZodObject<{
|
|
135
|
+
schemas: z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodLiteral<"all">, z.ZodRecord<z.ZodString, z.ZodLiteral<"all">>]>>]>;
|
|
136
|
+
}, z.core.$loose>>;
|
|
137
|
+
details: z.ZodOptional<z.ZodEnum<{
|
|
138
|
+
no: "no";
|
|
139
|
+
yes: "yes";
|
|
140
|
+
}>>;
|
|
141
|
+
transforms: z.ZodOptional<z.ZodEnum<{
|
|
142
|
+
no: "no";
|
|
143
|
+
yes: "yes";
|
|
144
|
+
}>>;
|
|
145
|
+
}, z.core.$loose>>>;
|
|
146
|
+
}, z.core.$loose>;
|
|
147
|
+
type PermissionsGraph = z.infer<typeof PermissionsGraph>;
|
|
148
|
+
//#endregion
|
|
149
|
+
export { PermissionsGraph as a, DownloadPermission as i, DataModelPermission as n, ViewDataPermission as o, DatabasePermissions as r, YesNoPermission as s, CreateQueriesPermission as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/poll.d.ts
|
|
2
|
+
type Backoff = "fixed" | "exponential";
|
|
3
|
+
interface PollOptions {
|
|
4
|
+
intervalMs?: number;
|
|
5
|
+
maxIntervalMs?: number;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
backoff?: Backoff;
|
|
8
|
+
signal?: AbortSignal;
|
|
9
|
+
}
|
|
10
|
+
declare const DEFAULT_INTERVAL_MS = 2000;
|
|
11
|
+
declare const DEFAULT_MAX_INTERVAL_MS = 30000;
|
|
12
|
+
declare const DEFAULT_TIMEOUT_MS = 600000;
|
|
13
|
+
declare function pollUntil<T>(fn: (signal: AbortSignal) => Promise<T>, done: (value: T) => boolean, opts?: PollOptions): Promise<T>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { PollOptions as a, DEFAULT_TIMEOUT_MS as i, DEFAULT_INTERVAL_MS as n, pollUntil as o, DEFAULT_MAX_INTERVAL_MS as r, Backoff as t };
|
package/dist/poll.d.ts
ADDED
package/dist/poll.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { TimeoutError } from "./errors.js";
|
|
2
|
+
import { combineAborts, throwIfAborted } from "./signal.js";
|
|
3
|
+
import { setTimeout } from "node:timers/promises";
|
|
4
|
+
//#region src/poll.ts
|
|
5
|
+
const DEFAULT_INTERVAL_MS = 2e3;
|
|
6
|
+
const DEFAULT_MAX_INTERVAL_MS = 3e4;
|
|
7
|
+
const DEFAULT_TIMEOUT_MS = 6e5;
|
|
8
|
+
async function pollUntil(fn, done, opts = {}) {
|
|
9
|
+
const intervalMs = opts.intervalMs ?? 2e3;
|
|
10
|
+
const maxIntervalMs = opts.maxIntervalMs ?? 3e4;
|
|
11
|
+
const timeoutMs = opts.timeoutMs ?? 6e5;
|
|
12
|
+
const backoff = opts.backoff ?? "fixed";
|
|
13
|
+
const combined = combineAborts(AbortSignal.timeout(timeoutMs), opts.signal);
|
|
14
|
+
let interval = intervalMs;
|
|
15
|
+
let attempts = 0;
|
|
16
|
+
while (true) {
|
|
17
|
+
throwIfAborted(opts.signal);
|
|
18
|
+
if (combined.aborted) throw pollTimeout(timeoutMs, attempts);
|
|
19
|
+
let value;
|
|
20
|
+
try {
|
|
21
|
+
value = await fn(combined);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
throwIfAborted(opts.signal);
|
|
24
|
+
if (combined.aborted) throw pollTimeout(timeoutMs, attempts);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
attempts += 1;
|
|
28
|
+
if (done(value)) return value;
|
|
29
|
+
try {
|
|
30
|
+
await setTimeout(interval, void 0, { signal: combined });
|
|
31
|
+
} catch (error) {
|
|
32
|
+
throwIfAborted(opts.signal);
|
|
33
|
+
if (combined.aborted) throw pollTimeout(timeoutMs, attempts);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
if (backoff === "exponential") interval = Math.min(interval * 2, maxIntervalMs);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function pollTimeout(timeoutMs, attempts) {
|
|
40
|
+
return new TimeoutError(`Polling timed out after ${timeoutMs}ms`, {
|
|
41
|
+
kind: "polling",
|
|
42
|
+
timeoutMs,
|
|
43
|
+
attempts
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
export { DEFAULT_INTERVAL_MS, DEFAULT_MAX_INTERVAL_MS, DEFAULT_TIMEOUT_MS, pollUntil };
|