UNPKG

get-notion-object-title

Version:
896 lines (895 loc) 30.4 kB
var M = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, N = {}, w = {}, L = {}, E = {}, z; function S() { if (z) return E; z = 1, Object.defineProperty(E, "__esModule", { value: !0 }), E.isObject = E.pick = E.assertNever = void 0; function e(u) { throw new Error(`Unexpected value should never occur: ${u}`); } E.assertNever = e; function a(u, h) { const b = h.map((f) => [f, u?.[f]]); return Object.fromEntries(b); } E.pick = a; function n(u) { return typeof u == "object" && u !== null; } return E.isObject = n, E; } var W; function x() { return W || (W = 1, function(e) { Object.defineProperty(e, "__esModule", { value: !0 }), e.logLevelSeverity = e.makeConsoleLogger = e.LogLevel = void 0; const a = S(); var n; (function(b) { b.DEBUG = "debug", b.INFO = "info", b.WARN = "warn", b.ERROR = "error"; })(n = e.LogLevel || (e.LogLevel = {})); function u(b) { return (f, v, g) => { console[f](`${b} ${f}:`, v, g); }; } e.makeConsoleLogger = u; function h(b) { switch (b) { case n.DEBUG: return 20; case n.INFO: return 40; case n.WARN: return 60; case n.ERROR: return 80; default: return (0, a.assertNever)(b); } } e.logLevelSeverity = h; }(L)), L; } var A = {}, V; function ee() { return V || (V = 1, function(e) { Object.defineProperty(e, "__esModule", { value: !0 }), e.buildRequestError = e.APIResponseError = e.UnknownHTTPResponseError = e.isHTTPResponseError = e.RequestTimeoutError = e.isNotionClientError = e.ClientErrorCode = e.APIErrorCode = void 0; const a = S(); var n; (function(d) { d.Unauthorized = "unauthorized", d.RestrictedResource = "restricted_resource", d.ObjectNotFound = "object_not_found", d.RateLimited = "rate_limited", d.InvalidJSON = "invalid_json", d.InvalidRequestURL = "invalid_request_url", d.InvalidRequest = "invalid_request", d.ValidationError = "validation_error", d.ConflictError = "conflict_error", d.InternalServerError = "internal_server_error", d.ServiceUnavailable = "service_unavailable"; })(n = e.APIErrorCode || (e.APIErrorCode = {})); var u; (function(d) { d.RequestTimeout = "notionhq_client_request_timeout", d.ResponseError = "notionhq_client_response_error"; })(u = e.ClientErrorCode || (e.ClientErrorCode = {})); class h extends Error { } function b(d) { return (0, a.isObject)(d) && d instanceof h; } e.isNotionClientError = b; function f(d, l) { return b(d) && d.code in l; } class v extends h { constructor(l = "Request to Notion API has timed out") { super(l), this.code = u.RequestTimeout, this.name = "RequestTimeoutError"; } static isRequestTimeoutError(l) { return f(l, { [u.RequestTimeout]: !0 }); } static rejectAfterTimeout(l, i) { return new Promise((p, m) => { const P = setTimeout(() => { m(new v()); }, i); l.then(p).catch(m).then(() => clearTimeout(P)); }); } } e.RequestTimeoutError = v; class g extends h { constructor(l) { super(l.message), this.name = "HTTPResponseError"; const { code: i, status: p, headers: m, rawBodyText: P } = l; this.code = i, this.status = p, this.headers = m, this.body = P; } } const _ = { [u.ResponseError]: !0, [n.Unauthorized]: !0, [n.RestrictedResource]: !0, [n.ObjectNotFound]: !0, [n.RateLimited]: !0, [n.InvalidJSON]: !0, [n.InvalidRequestURL]: !0, [n.InvalidRequest]: !0, [n.ValidationError]: !0, [n.ConflictError]: !0, [n.InternalServerError]: !0, [n.ServiceUnavailable]: !0 }; function R(d) { return !!f(d, _); } e.isHTTPResponseError = R; class c extends g { constructor(l) { var i; super({ ...l, code: u.ResponseError, message: (i = l.message) !== null && i !== void 0 ? i : `Request to Notion API failed with status: ${l.status}` }), this.name = "UnknownHTTPResponseError"; } static isUnknownHTTPResponseError(l) { return f(l, { [u.ResponseError]: !0 }); } } e.UnknownHTTPResponseError = c; const k = { [n.Unauthorized]: !0, [n.RestrictedResource]: !0, [n.ObjectNotFound]: !0, [n.RateLimited]: !0, [n.InvalidJSON]: !0, [n.InvalidRequestURL]: !0, [n.InvalidRequest]: !0, [n.ValidationError]: !0, [n.ConflictError]: !0, [n.InternalServerError]: !0, [n.ServiceUnavailable]: !0 }; class o extends g { constructor() { super(...arguments), this.name = "APIResponseError"; } static isAPIResponseError(l) { return f(l, k); } } e.APIResponseError = o; function r(d, l) { const i = U(l); return i !== void 0 ? new o({ code: i.code, message: i.message, headers: d.headers, status: d.status, rawBodyText: l }) : new c({ message: void 0, headers: d.headers, status: d.status, rawBodyText: l }); } e.buildRequestError = r; function U(d) { if (typeof d != "string") return; let l; try { l = JSON.parse(d); } catch { return; } if (!(!(0, a.isObject)(l) || typeof l.message != "string" || !B(l.code))) return { ...l, code: l.code, message: l.message }; } function B(d) { return typeof d == "string" && d in k; } }(A)), A; } var s = {}, J; function ae() { return J || (J = 1, Object.defineProperty(s, "__esModule", { value: !0 }), s.oauthToken = s.listComments = s.createComment = s.search = s.createDatabase = s.listDatabases = s.queryDatabase = s.updateDatabase = s.getDatabase = s.appendBlockChildren = s.listBlockChildren = s.deleteBlock = s.updateBlock = s.getBlock = s.getPageProperty = s.updatePage = s.getPage = s.createPage = s.listUsers = s.getUser = s.getSelf = void 0, s.getSelf = { method: "get", pathParams: [], queryParams: [], bodyParams: [], path: () => "users/me" }, s.getUser = { method: "get", pathParams: ["user_id"], queryParams: [], bodyParams: [], path: (e) => `users/${e.user_id}` }, s.listUsers = { method: "get", pathParams: [], queryParams: ["start_cursor", "page_size"], bodyParams: [], path: () => "users" }, s.createPage = { method: "post", pathParams: [], queryParams: [], bodyParams: ["parent", "properties", "icon", "cover", "content", "children"], path: () => "pages" }, s.getPage = { method: "get", pathParams: ["page_id"], queryParams: ["filter_properties"], bodyParams: [], path: (e) => `pages/${e.page_id}` }, s.updatePage = { method: "patch", pathParams: ["page_id"], queryParams: [], bodyParams: ["properties", "icon", "cover", "archived", "in_trash"], path: (e) => `pages/${e.page_id}` }, s.getPageProperty = { method: "get", pathParams: ["page_id", "property_id"], queryParams: ["start_cursor", "page_size"], bodyParams: [], path: (e) => `pages/${e.page_id}/properties/${e.property_id}` }, s.getBlock = { method: "get", pathParams: ["block_id"], queryParams: [], bodyParams: [], path: (e) => `blocks/${e.block_id}` }, s.updateBlock = { method: "patch", pathParams: ["block_id"], queryParams: [], bodyParams: [ "embed", "type", "archived", "in_trash", "bookmark", "image", "video", "pdf", "file", "audio", "code", "equation", "divider", "breadcrumb", "table_of_contents", "link_to_page", "table_row", "heading_1", "heading_2", "heading_3", "paragraph", "bulleted_list_item", "numbered_list_item", "quote", "to_do", "toggle", "template", "callout", "synced_block", "table" ], path: (e) => `blocks/${e.block_id}` }, s.deleteBlock = { method: "delete", pathParams: ["block_id"], queryParams: [], bodyParams: [], path: (e) => `blocks/${e.block_id}` }, s.listBlockChildren = { method: "get", pathParams: ["block_id"], queryParams: ["start_cursor", "page_size"], bodyParams: [], path: (e) => `blocks/${e.block_id}/children` }, s.appendBlockChildren = { method: "patch", pathParams: ["block_id"], queryParams: [], bodyParams: ["children", "after"], path: (e) => `blocks/${e.block_id}/children` }, s.getDatabase = { method: "get", pathParams: ["database_id"], queryParams: [], bodyParams: [], path: (e) => `databases/${e.database_id}` }, s.updateDatabase = { method: "patch", pathParams: ["database_id"], queryParams: [], bodyParams: [ "title", "description", "icon", "cover", "properties", "is_inline", "archived", "in_trash" ], path: (e) => `databases/${e.database_id}` }, s.queryDatabase = { method: "post", pathParams: ["database_id"], queryParams: ["filter_properties"], bodyParams: [ "sorts", "filter", "start_cursor", "page_size", "archived", "in_trash" ], path: (e) => `databases/${e.database_id}/query` }, s.listDatabases = { method: "get", pathParams: [], queryParams: ["start_cursor", "page_size"], bodyParams: [], path: () => "databases" }, s.createDatabase = { method: "post", pathParams: [], queryParams: [], bodyParams: [ "parent", "properties", "icon", "cover", "title", "description", "is_inline" ], path: () => "databases" }, s.search = { method: "post", pathParams: [], queryParams: [], bodyParams: ["sort", "query", "start_cursor", "page_size", "filter"], path: () => "search" }, s.createComment = { method: "post", pathParams: [], queryParams: [], bodyParams: ["parent", "rich_text", "discussion_id"], path: () => "comments" }, s.listComments = { method: "get", pathParams: [], queryParams: ["block_id", "start_cursor", "page_size"], bodyParams: [], path: () => "comments" }, s.oauthToken = { method: "post", pathParams: [], queryParams: [], bodyParams: ["grant_type", "code", "redirect_uri", "external_account"], path: () => "oauth/token" }), s; } var O = { exports: {} }, G; function ie() { return G || (G = 1, function(e, a) { var n = function() { if (typeof self < "u") return self; if (typeof window < "u") return window; if (typeof M < "u") return M; throw new Error("unable to locate global object"); }, u = n(); e.exports = a = u.fetch, u.fetch && (a.default = u.fetch.bind(u)), a.Headers = u.Headers, a.Request = u.Request, a.Response = u.Response; }(O, O.exports)), O.exports; } const oe = "@notionhq/client", ne = "2.2.15", se = { name: oe, version: ne }; var K; function ue() { if (K) return w; K = 1; var e = w && w.__classPrivateFieldSet || function(l, i, p, m, P) { if (m === "m") throw new TypeError("Private method is not writable"); if (m === "a" && !P) throw new TypeError("Private accessor was defined without a setter"); if (typeof i == "function" ? l !== i || !P : !i.has(l)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return m === "a" ? P.call(l, p) : P ? P.value = p : i.set(l, p), p; }, a = w && w.__classPrivateFieldGet || function(l, i, p, m) { if (p === "a" && !m) throw new TypeError("Private accessor was defined without a getter"); if (typeof i == "function" ? l !== i || !m : !i.has(l)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return p === "m" ? m : p === "a" ? m.call(l) : m ? m.value : i.get(l); }, n, u, h, b, f, v, g, _, R; Object.defineProperty(w, "__esModule", { value: !0 }); const c = x(), k = ee(), o = S(), r = ae(), U = ie(), B = se; let d = class te { constructor(i) { var p, m, P, C, F, j; n.set(this, void 0), u.set(this, void 0), h.set(this, void 0), b.set(this, void 0), f.set(this, void 0), v.set(this, void 0), g.set(this, void 0), _.set(this, void 0), R.set(this, void 0), this.blocks = { /** * Retrieve block */ retrieve: (t) => this.request({ path: r.getBlock.path(t), method: r.getBlock.method, query: (0, o.pick)(t, r.getBlock.queryParams), body: (0, o.pick)(t, r.getBlock.bodyParams), auth: t?.auth }), /** * Update block */ update: (t) => this.request({ path: r.updateBlock.path(t), method: r.updateBlock.method, query: (0, o.pick)(t, r.updateBlock.queryParams), body: (0, o.pick)(t, r.updateBlock.bodyParams), auth: t?.auth }), /** * Delete block */ delete: (t) => this.request({ path: r.deleteBlock.path(t), method: r.deleteBlock.method, query: (0, o.pick)(t, r.deleteBlock.queryParams), body: (0, o.pick)(t, r.deleteBlock.bodyParams), auth: t?.auth }), children: { /** * Append block children */ append: (t) => this.request({ path: r.appendBlockChildren.path(t), method: r.appendBlockChildren.method, query: (0, o.pick)(t, r.appendBlockChildren.queryParams), body: (0, o.pick)(t, r.appendBlockChildren.bodyParams), auth: t?.auth }), /** * Retrieve block children */ list: (t) => this.request({ path: r.listBlockChildren.path(t), method: r.listBlockChildren.method, query: (0, o.pick)(t, r.listBlockChildren.queryParams), body: (0, o.pick)(t, r.listBlockChildren.bodyParams), auth: t?.auth }) } }, this.databases = { /** * List databases * * @deprecated Please use `search` */ list: (t) => this.request({ path: r.listDatabases.path(), method: r.listDatabases.method, query: (0, o.pick)(t, r.listDatabases.queryParams), body: (0, o.pick)(t, r.listDatabases.bodyParams), auth: t?.auth }), /** * Retrieve a database */ retrieve: (t) => this.request({ path: r.getDatabase.path(t), method: r.getDatabase.method, query: (0, o.pick)(t, r.getDatabase.queryParams), body: (0, o.pick)(t, r.getDatabase.bodyParams), auth: t?.auth }), /** * Query a database */ query: (t) => this.request({ path: r.queryDatabase.path(t), method: r.queryDatabase.method, query: (0, o.pick)(t, r.queryDatabase.queryParams), body: (0, o.pick)(t, r.queryDatabase.bodyParams), auth: t?.auth }), /** * Create a database */ create: (t) => this.request({ path: r.createDatabase.path(), method: r.createDatabase.method, query: (0, o.pick)(t, r.createDatabase.queryParams), body: (0, o.pick)(t, r.createDatabase.bodyParams), auth: t?.auth }), /** * Update a database */ update: (t) => this.request({ path: r.updateDatabase.path(t), method: r.updateDatabase.method, query: (0, o.pick)(t, r.updateDatabase.queryParams), body: (0, o.pick)(t, r.updateDatabase.bodyParams), auth: t?.auth }) }, this.pages = { /** * Create a page */ create: (t) => this.request({ path: r.createPage.path(), method: r.createPage.method, query: (0, o.pick)(t, r.createPage.queryParams), body: (0, o.pick)(t, r.createPage.bodyParams), auth: t?.auth }), /** * Retrieve a page */ retrieve: (t) => this.request({ path: r.getPage.path(t), method: r.getPage.method, query: (0, o.pick)(t, r.getPage.queryParams), body: (0, o.pick)(t, r.getPage.bodyParams), auth: t?.auth }), /** * Update page properties */ update: (t) => this.request({ path: r.updatePage.path(t), method: r.updatePage.method, query: (0, o.pick)(t, r.updatePage.queryParams), body: (0, o.pick)(t, r.updatePage.bodyParams), auth: t?.auth }), properties: { /** * Retrieve page property */ retrieve: (t) => this.request({ path: r.getPageProperty.path(t), method: r.getPageProperty.method, query: (0, o.pick)(t, r.getPageProperty.queryParams), body: (0, o.pick)(t, r.getPageProperty.bodyParams), auth: t?.auth }) } }, this.users = { /** * Retrieve a user */ retrieve: (t) => this.request({ path: r.getUser.path(t), method: r.getUser.method, query: (0, o.pick)(t, r.getUser.queryParams), body: (0, o.pick)(t, r.getUser.bodyParams), auth: t?.auth }), /** * List all users */ list: (t) => this.request({ path: r.listUsers.path(), method: r.listUsers.method, query: (0, o.pick)(t, r.listUsers.queryParams), body: (0, o.pick)(t, r.listUsers.bodyParams), auth: t?.auth }), /** * Get details about bot */ me: (t) => this.request({ path: r.getSelf.path(), method: r.getSelf.method, query: (0, o.pick)(t, r.getSelf.queryParams), body: (0, o.pick)(t, r.getSelf.bodyParams), auth: t?.auth }) }, this.comments = { /** * Create a comment */ create: (t) => this.request({ path: r.createComment.path(), method: r.createComment.method, query: (0, o.pick)(t, r.createComment.queryParams), body: (0, o.pick)(t, r.createComment.bodyParams), auth: t?.auth }), /** * List comments */ list: (t) => this.request({ path: r.listComments.path(), method: r.listComments.method, query: (0, o.pick)(t, r.listComments.queryParams), body: (0, o.pick)(t, r.listComments.bodyParams), auth: t?.auth }) }, this.search = (t) => this.request({ path: r.search.path(), method: r.search.method, query: (0, o.pick)(t, r.search.queryParams), body: (0, o.pick)(t, r.search.bodyParams), auth: t?.auth }), this.oauth = { /** * Get token */ token: (t) => this.request({ path: r.oauthToken.path(), method: r.oauthToken.method, query: (0, o.pick)(t, r.oauthToken.queryParams), body: (0, o.pick)(t, r.oauthToken.bodyParams), auth: { client_id: t.client_id, client_secret: t.client_secret } }) }, e(this, n, i?.auth, "f"), e(this, u, (p = i?.logLevel) !== null && p !== void 0 ? p : c.LogLevel.WARN, "f"), e(this, h, (m = i?.logger) !== null && m !== void 0 ? m : (0, c.makeConsoleLogger)(B.name), "f"), e(this, b, ((P = i?.baseUrl) !== null && P !== void 0 ? P : "https://api.notion.com") + "/v1/", "f"), e(this, f, (C = i?.timeoutMs) !== null && C !== void 0 ? C : 6e4, "f"), e(this, v, (F = i?.notionVersion) !== null && F !== void 0 ? F : te.defaultNotionVersion, "f"), e(this, g, (j = i?.fetch) !== null && j !== void 0 ? j : U.default, "f"), e(this, _, i?.agent, "f"), e(this, R, `notionhq-client/${B.version}`, "f"); } /** * Sends a request. * * @param path * @param method * @param query * @param body * @returns */ async request({ path: i, method: p, query: m, body: P, auth: C }) { this.log(c.LogLevel.INFO, "request start", { method: p, path: i }); const F = !P || Object.entries(P).length === 0 ? void 0 : JSON.stringify(P), j = new URL(`${a(this, b, "f")}${i}`); if (m) for (const [q, T] of Object.entries(m)) T !== void 0 && (Array.isArray(T) ? T.forEach((D) => j.searchParams.append(q, decodeURIComponent(D))) : j.searchParams.append(q, String(T))); let t; if (typeof C == "object") { const q = `${C.client_id}:${C.client_secret}`; t = { authorization: `Basic ${Buffer.from(q).toString("base64")}` }; } else t = this.authAsHeaders(C); const H = { ...t, "Notion-Version": a(this, v, "f"), "user-agent": a(this, R, "f") }; F !== void 0 && (H["content-type"] = "application/json"); try { const q = await k.RequestTimeoutError.rejectAfterTimeout(a(this, g, "f").call(this, j.toString(), { method: p.toUpperCase(), headers: H, body: F, agent: a(this, _, "f") }), a(this, f, "f")), T = await q.text(); if (!q.ok) throw (0, k.buildRequestError)(q, T); const D = JSON.parse(T); return this.log(c.LogLevel.INFO, "request success", { method: p, path: i }), D; } catch (q) { throw (0, k.isNotionClientError)(q) && (this.log(c.LogLevel.WARN, "request fail", { code: q.code, message: q.message }), (0, k.isHTTPResponseError)(q) && this.log(c.LogLevel.DEBUG, "failed response body", { body: q.body })), q; } } /** * Emits a log message to the console. * * @param level The level for this message * @param args Arguments to send to the console */ log(i, p, m) { (0, c.logLevelSeverity)(i) >= (0, c.logLevelSeverity)(a(this, u, "f")) && a(this, h, "f").call(this, i, p, m); } /** * Transforms an API key or access token into a headers object suitable for an HTTP request. * * This method uses the instance's value as the default when the input is undefined. If neither are defined, it returns * an empty object * * @param auth API key or access token * @returns headers key-value object */ authAsHeaders(i) { const p = {}, m = i ?? a(this, n, "f"); return m !== void 0 && (p.authorization = `Bearer ${m}`), p; } }; return w.default = d, n = /* @__PURE__ */ new WeakMap(), u = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), b = /* @__PURE__ */ new WeakMap(), f = /* @__PURE__ */ new WeakMap(), v = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), _ = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap(), d.defaultNotionVersion = "2022-06-28", w; } var y = {}, Q; function de() { if (Q) return y; Q = 1, Object.defineProperty(y, "__esModule", { value: !0 }), y.isMentionRichTextItemResponse = y.isEquationRichTextItemResponse = y.isTextRichTextItemResponse = y.isFullComment = y.isFullUser = y.isFullPageOrDatabase = y.isFullDatabase = y.isFullPage = y.isFullBlock = y.collectPaginatedAPI = y.iteratePaginatedAPI = void 0; async function* e(c, k) { let o = k.start_cursor; do { const r = await c({ ...k, start_cursor: o }); yield* r.results, o = r.next_cursor; } while (o); } y.iteratePaginatedAPI = e; async function a(c, k) { const o = []; for await (const r of e(c, k)) o.push(r); return o; } y.collectPaginatedAPI = a; function n(c) { return c.object === "block" && "type" in c; } y.isFullBlock = n; function u(c) { return c.object === "page" && "url" in c; } y.isFullPage = u; function h(c) { return c.object === "database" && "title" in c; } y.isFullDatabase = h; function b(c) { return c.object === "database" ? h(c) : u(c); } y.isFullPageOrDatabase = b; function f(c) { return "type" in c; } y.isFullUser = f; function v(c) { return "created_by" in c; } y.isFullComment = v; function g(c) { return c.type === "text"; } y.isTextRichTextItemResponse = g; function _(c) { return c.type === "equation"; } y.isEquationRichTextItemResponse = _; function R(c) { return c.type === "mention"; } return y.isMentionRichTextItemResponse = R, y; } var X; function le() { return X || (X = 1, function(e) { Object.defineProperty(e, "__esModule", { value: !0 }), e.isFullPageOrDatabase = e.isFullComment = e.isFullUser = e.isFullPage = e.isFullDatabase = e.isFullBlock = e.iteratePaginatedAPI = e.collectPaginatedAPI = e.isNotionClientError = e.RequestTimeoutError = e.UnknownHTTPResponseError = e.APIResponseError = e.ClientErrorCode = e.APIErrorCode = e.LogLevel = e.Client = void 0; var a = ue(); Object.defineProperty(e, "Client", { enumerable: !0, get: function() { return a.default; } }); var n = x(); Object.defineProperty(e, "LogLevel", { enumerable: !0, get: function() { return n.LogLevel; } }); var u = ee(); Object.defineProperty(e, "APIErrorCode", { enumerable: !0, get: function() { return u.APIErrorCode; } }), Object.defineProperty(e, "ClientErrorCode", { enumerable: !0, get: function() { return u.ClientErrorCode; } }), Object.defineProperty(e, "APIResponseError", { enumerable: !0, get: function() { return u.APIResponseError; } }), Object.defineProperty(e, "UnknownHTTPResponseError", { enumerable: !0, get: function() { return u.UnknownHTTPResponseError; } }), Object.defineProperty(e, "RequestTimeoutError", { enumerable: !0, get: function() { return u.RequestTimeoutError; } }), Object.defineProperty(e, "isNotionClientError", { enumerable: !0, get: function() { return u.isNotionClientError; } }); var h = de(); Object.defineProperty(e, "collectPaginatedAPI", { enumerable: !0, get: function() { return h.collectPaginatedAPI; } }), Object.defineProperty(e, "iteratePaginatedAPI", { enumerable: !0, get: function() { return h.iteratePaginatedAPI; } }), Object.defineProperty(e, "isFullBlock", { enumerable: !0, get: function() { return h.isFullBlock; } }), Object.defineProperty(e, "isFullDatabase", { enumerable: !0, get: function() { return h.isFullDatabase; } }), Object.defineProperty(e, "isFullPage", { enumerable: !0, get: function() { return h.isFullPage; } }), Object.defineProperty(e, "isFullUser", { enumerable: !0, get: function() { return h.isFullUser; } }), Object.defineProperty(e, "isFullComment", { enumerable: !0, get: function() { return h.isFullComment; } }), Object.defineProperty(e, "isFullPageOrDatabase", { enumerable: !0, get: function() { return h.isFullPageOrDatabase; } }); }(N)), N; } var Y = le(); const re = (e) => e.map((a) => a.plain_text).join(""), ce = (e) => { let a, n; return e[e.type].external ? a = e[e.type].external.url : e[e.type].file ? a = e[e.type].file.url : e[e.type].url ? a = e[e.type].url : a = "[Missing case for media block types]: " + e.type, e[e.type].caption.length ? (n = re(e[e.type].caption), n + ": " + a) : a; }, he = (e) => { let a; if (e[e.type].rich_text) a = re(e[e.type].rich_text); else switch (e.type) { case "unsupported": a = "[Unsupported block type]"; break; case "bookmark": a = e.bookmark.url; break; case "child_database": a = e.child_database.title; break; case "child_page": a = e.child_page.title; break; case "embed": case "video": case "file": case "image": case "pdf": a = ce(e); break; case "equation": a = e.equation.expression; break; case "link_preview": a = e.link_preview.url; break; case "synced_block": a = e.synced_block.synced_from ? "This block is synced with a block with the following ID: " + e.synced_block.synced_from[e.synced_block.synced_from.type] : "Source sync block that another blocked is synced with."; break; case "table": a = "Table width: " + e.table.table_width; break; case "table_of_contents": a = "ToC color: " + e.table_of_contents.color; break; case "breadcrumb": case "column_list": case "divider": a = "No text available"; break; default: a = "[Needs case added]"; break; } return e.has_children && (a = a + " (Has children)"), e.type + ": " + a; }, Z = (e) => e && "emoji" in e ? e.emoji : null, $ = (e) => Array.isArray(e) ? e.map((a) => a.plain_text).join("") : "", I = (e) => { if (!e) return ""; if ("rich_text" in e) return $(e.rich_text); if ("title" in e) return $(e.title); }, me = (e, a = { emoji: !0 }) => { var n, u; const h = e; if (Y.isFullPage(h) && h.object === "page" && h.properties) { const f = ["title", "Page", "Name", "Topic"].find((_) => I(h.properties[_])), v = (n = Z(h.icon)) !== null && n !== void 0 ? n : ""; if (f) return a.emoji ? `${v}${I(h.properties[f])}` : I(h.properties[f]); const g = Object.keys(h.properties).reverse().map((_) => I(h.properties[_])).filter((_) => _).reduce((_, R) => `${_} ${R}`, ""); return a.emoji ? `${v}${g}` : g; } const b = e; if (Y.isFullDatabase(b)) { const f = $(b.title); return a.emoji ? `${(u = Z(h.icon)) !== null && u !== void 0 ? u : ""}${f}` : f; } return e?.type !== void 0 ? he(e) : "Untitled"; }; export { me as getNotionObjectTitle };