@blazeo.com/calendar-client 1.0.15 → 1.0.17
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/dist/index.d.ts +29 -0
- package/dist/index.js +108 -2
- package/dist/index.mjs +108 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -138,6 +138,35 @@ export const LeadModel: {
|
|
|
138
138
|
getRaw(leadId: string): Promise<{ status: string; data?: unknown; message?: string }>;
|
|
139
139
|
get(leadId: string): Promise<unknown>;
|
|
140
140
|
getByEmail(email: string, companyKey: string): Promise<unknown>;
|
|
141
|
+
createLead(payload: {
|
|
142
|
+
email: string;
|
|
143
|
+
companyKey: string;
|
|
144
|
+
name?: string;
|
|
145
|
+
phone?: string;
|
|
146
|
+
source?: string;
|
|
147
|
+
leadType?: 'sales' | 'service' | 'others' | number;
|
|
148
|
+
referrerLink?: string;
|
|
149
|
+
}): Promise<unknown>;
|
|
150
|
+
updateLead(payload: {
|
|
151
|
+
leadId: string;
|
|
152
|
+
email?: string;
|
|
153
|
+
companyKey?: string;
|
|
154
|
+
name?: string;
|
|
155
|
+
phone?: string;
|
|
156
|
+
source?: string;
|
|
157
|
+
leadType?: 'sales' | 'service' | 'others' | number;
|
|
158
|
+
referrerLink?: string;
|
|
159
|
+
}): Promise<unknown>;
|
|
160
|
+
deleteLead(leadId: string): Promise<{ status: string; data?: unknown; message?: string }>;
|
|
161
|
+
requestExport(
|
|
162
|
+
companyKey: string,
|
|
163
|
+
opts?: {
|
|
164
|
+
notifyPath?: string;
|
|
165
|
+
notify_path?: string;
|
|
166
|
+
consumer?: string;
|
|
167
|
+
Consumer?: string;
|
|
168
|
+
}
|
|
169
|
+
): Promise<{ status: string; data?: unknown; message?: string }>;
|
|
141
170
|
getByCompany(
|
|
142
171
|
companyKey: string,
|
|
143
172
|
opts?: {
|
package/dist/index.js
CHANGED
|
@@ -147,7 +147,7 @@ async function request(baseUrl, fetchFn, path, options = {}) {
|
|
|
147
147
|
}
|
|
148
148
|
function mergeConsumerHeader(env, opts) {
|
|
149
149
|
const headers = { ...opts.headers || {} };
|
|
150
|
-
if (env == null ? void 0 : env.consumer) headers["Consumer"] = env.consumer;
|
|
150
|
+
if (!headers["Consumer"] && (env == null ? void 0 : env.consumer)) headers["Consumer"] = env.consumer;
|
|
151
151
|
return { ...opts, headers };
|
|
152
152
|
}
|
|
153
153
|
function createRequestHelpers(self, getEnv9) {
|
|
@@ -1963,6 +1963,17 @@ var import_mobx_state_tree17 = require("mobx-state-tree");
|
|
|
1963
1963
|
function mapLeadFromApi(d) {
|
|
1964
1964
|
if (!d) return d;
|
|
1965
1965
|
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1966
|
+
const leadTypeRaw = pick("leadType", "LeadType", "lead_type");
|
|
1967
|
+
let leadType = 2;
|
|
1968
|
+
if (typeof leadTypeRaw === "number" && Number.isFinite(leadTypeRaw)) {
|
|
1969
|
+
leadType = leadTypeRaw;
|
|
1970
|
+
} else if (typeof leadTypeRaw === "string" && leadTypeRaw.trim() !== "") {
|
|
1971
|
+
const lowered = leadTypeRaw.trim().toLowerCase();
|
|
1972
|
+
if (lowered === "sales") leadType = 0;
|
|
1973
|
+
else if (lowered === "service") leadType = 1;
|
|
1974
|
+
else if (lowered === "others") leadType = 2;
|
|
1975
|
+
else if (!Number.isNaN(Number(leadTypeRaw))) leadType = Number(leadTypeRaw);
|
|
1976
|
+
}
|
|
1966
1977
|
return {
|
|
1967
1978
|
id: pick("id", "Id") ?? null,
|
|
1968
1979
|
leadId: pick("leadId", "LeadId", "lead_id") ?? "",
|
|
@@ -1971,6 +1982,8 @@ function mapLeadFromApi(d) {
|
|
|
1971
1982
|
phone: pick("phone", "Phone") ?? "",
|
|
1972
1983
|
companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
|
|
1973
1984
|
source: pick("source", "Source") ?? "",
|
|
1985
|
+
leadType,
|
|
1986
|
+
referrerLink: pick("referrerLink", "ReferrerLink", "referrer_link") ?? "",
|
|
1974
1987
|
createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1975
1988
|
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1976
1989
|
};
|
|
@@ -1983,10 +1996,12 @@ var LeadModel = import_mobx_state_tree17.types.model("Lead", {
|
|
|
1983
1996
|
phone: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
|
|
1984
1997
|
companyKey: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
|
|
1985
1998
|
source: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
|
|
1999
|
+
leadType: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.number, 2),
|
|
2000
|
+
referrerLink: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.string, ""),
|
|
1986
2001
|
createdOn: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.string), null),
|
|
1987
2002
|
modifiedOn: import_mobx_state_tree17.types.optional(import_mobx_state_tree17.types.maybeNull(import_mobx_state_tree17.types.string), null)
|
|
1988
2003
|
}).actions((self) => {
|
|
1989
|
-
const { reqGet } = createRequestHelpers(self, import_mobx_state_tree17.getEnv);
|
|
2004
|
+
const { reqGet, reqPost } = createRequestHelpers(self, import_mobx_state_tree17.getEnv);
|
|
1990
2005
|
return {
|
|
1991
2006
|
/** GET /lead/get – fetch this lead by leadId */
|
|
1992
2007
|
async get() {
|
|
@@ -2012,6 +2027,61 @@ var LeadModel = import_mobx_state_tree17.types.model("Lead", {
|
|
|
2012
2027
|
async getByCompany(opts = {}) {
|
|
2013
2028
|
if (!self.companyKey) return null;
|
|
2014
2029
|
return LeadModel.getByCompany(self.companyKey, opts);
|
|
2030
|
+
},
|
|
2031
|
+
/** POST /lead/create – create this lead */
|
|
2032
|
+
async createLead() {
|
|
2033
|
+
const payload = {
|
|
2034
|
+
email: self.email,
|
|
2035
|
+
name: self.name,
|
|
2036
|
+
phone: self.phone,
|
|
2037
|
+
companyKey: self.companyKey,
|
|
2038
|
+
source: self.source,
|
|
2039
|
+
leadType: self.leadType,
|
|
2040
|
+
referrerLink: self.referrerLink
|
|
2041
|
+
};
|
|
2042
|
+
const res = await reqPost("/lead/create", payload);
|
|
2043
|
+
if (res.status === "success" && res.data) {
|
|
2044
|
+
(0, import_mobx_state_tree17.applySnapshot)(self, mapLeadFromApi(res.data));
|
|
2045
|
+
}
|
|
2046
|
+
return res;
|
|
2047
|
+
},
|
|
2048
|
+
/** POST /lead/update – update this lead */
|
|
2049
|
+
async updateLead() {
|
|
2050
|
+
if (!self.leadId || self.leadId === "new") {
|
|
2051
|
+
return { status: "failure", message: "leadId required" };
|
|
2052
|
+
}
|
|
2053
|
+
const payload = {
|
|
2054
|
+
leadId: self.leadId,
|
|
2055
|
+
email: self.email,
|
|
2056
|
+
name: self.name,
|
|
2057
|
+
phone: self.phone,
|
|
2058
|
+
companyKey: self.companyKey,
|
|
2059
|
+
source: self.source,
|
|
2060
|
+
leadType: self.leadType,
|
|
2061
|
+
referrerLink: self.referrerLink
|
|
2062
|
+
};
|
|
2063
|
+
const res = await reqPost("/lead/update", payload);
|
|
2064
|
+
if (res.status === "success" && res.data) {
|
|
2065
|
+
(0, import_mobx_state_tree17.applySnapshot)(self, mapLeadFromApi(res.data));
|
|
2066
|
+
}
|
|
2067
|
+
return res;
|
|
2068
|
+
},
|
|
2069
|
+
/** GET /lead/delete – delete this lead by leadId */
|
|
2070
|
+
async deleteLead() {
|
|
2071
|
+
if (!self.leadId || self.leadId === "new") {
|
|
2072
|
+
return { status: "failure", message: "leadId required" };
|
|
2073
|
+
}
|
|
2074
|
+
return reqGet("/lead/delete", { lead_id: self.leadId });
|
|
2075
|
+
},
|
|
2076
|
+
/**
|
|
2077
|
+
* POST /lead/export/request – queue async full CSV export for self.companyKey (no list filters).
|
|
2078
|
+
* @param {object} [opts] – { notifyPath?, consumer? } consumer = Consumer header for completion webhook
|
|
2079
|
+
*/
|
|
2080
|
+
async requestLeadExport(opts = {}) {
|
|
2081
|
+
if (!self.companyKey || String(self.companyKey).trim() === "") {
|
|
2082
|
+
return { status: "failure", message: "companyKey required on model" };
|
|
2083
|
+
}
|
|
2084
|
+
return LeadModel.requestExport(self.companyKey, opts);
|
|
2015
2085
|
}
|
|
2016
2086
|
};
|
|
2017
2087
|
});
|
|
@@ -2066,6 +2136,42 @@ LeadModel.getByCompany = async (companyKey, opts = {}) => {
|
|
|
2066
2136
|
}
|
|
2067
2137
|
return null;
|
|
2068
2138
|
};
|
|
2139
|
+
LeadModel.createLead = async (payload) => {
|
|
2140
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
2141
|
+
const res = await reqPost("/lead/create", payload);
|
|
2142
|
+
if (res.status === "success" && res.data) {
|
|
2143
|
+
return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
|
|
2144
|
+
}
|
|
2145
|
+
return null;
|
|
2146
|
+
};
|
|
2147
|
+
LeadModel.updateLead = async (payload) => {
|
|
2148
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
2149
|
+
const res = await reqPost("/lead/update", payload);
|
|
2150
|
+
if (res.status === "success" && res.data) {
|
|
2151
|
+
return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
|
|
2152
|
+
}
|
|
2153
|
+
return null;
|
|
2154
|
+
};
|
|
2155
|
+
LeadModel.deleteLead = async (leadId) => {
|
|
2156
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2157
|
+
return reqGet("/lead/delete", { lead_id: leadId });
|
|
2158
|
+
};
|
|
2159
|
+
LeadModel.requestExport = async (companyKey, opts = {}) => {
|
|
2160
|
+
const ck = companyKey != null ? String(companyKey).trim() : "";
|
|
2161
|
+
if (!ck) return { status: "failure", message: "companyKey required" };
|
|
2162
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
2163
|
+
const body = { company_key: ck };
|
|
2164
|
+
const np = opts.notifyPath ?? opts.notify_path;
|
|
2165
|
+
if (np != null && String(np).trim() !== "") {
|
|
2166
|
+
body.notify_path = String(np).trim();
|
|
2167
|
+
}
|
|
2168
|
+
const headers = {};
|
|
2169
|
+
const consumer = opts.consumer ?? opts.Consumer;
|
|
2170
|
+
if (consumer != null && String(consumer).trim() !== "") {
|
|
2171
|
+
headers.Consumer = String(consumer).trim();
|
|
2172
|
+
}
|
|
2173
|
+
return reqPost("/lead/export/request", body, void 0, { headers });
|
|
2174
|
+
};
|
|
2069
2175
|
LeadModel.getSources = async (companyKey) => {
|
|
2070
2176
|
var _a;
|
|
2071
2177
|
if (!companyKey || String(companyKey).trim() === "") return [];
|
package/dist/index.mjs
CHANGED
|
@@ -94,7 +94,7 @@ async function request(baseUrl, fetchFn, path, options = {}) {
|
|
|
94
94
|
}
|
|
95
95
|
function mergeConsumerHeader(env, opts) {
|
|
96
96
|
const headers = { ...opts.headers || {} };
|
|
97
|
-
if (env == null ? void 0 : env.consumer) headers["Consumer"] = env.consumer;
|
|
97
|
+
if (!headers["Consumer"] && (env == null ? void 0 : env.consumer)) headers["Consumer"] = env.consumer;
|
|
98
98
|
return { ...opts, headers };
|
|
99
99
|
}
|
|
100
100
|
function createRequestHelpers(self, getEnv9) {
|
|
@@ -1910,6 +1910,17 @@ import { types as types17, getEnv as getEnv7, applySnapshot as applySnapshot7, g
|
|
|
1910
1910
|
function mapLeadFromApi(d) {
|
|
1911
1911
|
if (!d) return d;
|
|
1912
1912
|
const pick = (...keys) => keys.reduce((v, k) => v ?? d[k], void 0);
|
|
1913
|
+
const leadTypeRaw = pick("leadType", "LeadType", "lead_type");
|
|
1914
|
+
let leadType = 2;
|
|
1915
|
+
if (typeof leadTypeRaw === "number" && Number.isFinite(leadTypeRaw)) {
|
|
1916
|
+
leadType = leadTypeRaw;
|
|
1917
|
+
} else if (typeof leadTypeRaw === "string" && leadTypeRaw.trim() !== "") {
|
|
1918
|
+
const lowered = leadTypeRaw.trim().toLowerCase();
|
|
1919
|
+
if (lowered === "sales") leadType = 0;
|
|
1920
|
+
else if (lowered === "service") leadType = 1;
|
|
1921
|
+
else if (lowered === "others") leadType = 2;
|
|
1922
|
+
else if (!Number.isNaN(Number(leadTypeRaw))) leadType = Number(leadTypeRaw);
|
|
1923
|
+
}
|
|
1913
1924
|
return {
|
|
1914
1925
|
id: pick("id", "Id") ?? null,
|
|
1915
1926
|
leadId: pick("leadId", "LeadId", "lead_id") ?? "",
|
|
@@ -1918,6 +1929,8 @@ function mapLeadFromApi(d) {
|
|
|
1918
1929
|
phone: pick("phone", "Phone") ?? "",
|
|
1919
1930
|
companyKey: pick("companyKey", "CompanyKey", "company_key") ?? "",
|
|
1920
1931
|
source: pick("source", "Source") ?? "",
|
|
1932
|
+
leadType,
|
|
1933
|
+
referrerLink: pick("referrerLink", "ReferrerLink", "referrer_link") ?? "",
|
|
1921
1934
|
createdOn: pick("createdOn", "CreatedOn", "created_on") ?? null,
|
|
1922
1935
|
modifiedOn: pick("modifiedOn", "ModifiedOn", "modified_on") ?? null
|
|
1923
1936
|
};
|
|
@@ -1930,10 +1943,12 @@ var LeadModel = types17.model("Lead", {
|
|
|
1930
1943
|
phone: types17.optional(types17.string, ""),
|
|
1931
1944
|
companyKey: types17.optional(types17.string, ""),
|
|
1932
1945
|
source: types17.optional(types17.string, ""),
|
|
1946
|
+
leadType: types17.optional(types17.number, 2),
|
|
1947
|
+
referrerLink: types17.optional(types17.string, ""),
|
|
1933
1948
|
createdOn: types17.optional(types17.maybeNull(types17.string), null),
|
|
1934
1949
|
modifiedOn: types17.optional(types17.maybeNull(types17.string), null)
|
|
1935
1950
|
}).actions((self) => {
|
|
1936
|
-
const { reqGet } = createRequestHelpers(self, getEnv7);
|
|
1951
|
+
const { reqGet, reqPost } = createRequestHelpers(self, getEnv7);
|
|
1937
1952
|
return {
|
|
1938
1953
|
/** GET /lead/get – fetch this lead by leadId */
|
|
1939
1954
|
async get() {
|
|
@@ -1959,6 +1974,61 @@ var LeadModel = types17.model("Lead", {
|
|
|
1959
1974
|
async getByCompany(opts = {}) {
|
|
1960
1975
|
if (!self.companyKey) return null;
|
|
1961
1976
|
return LeadModel.getByCompany(self.companyKey, opts);
|
|
1977
|
+
},
|
|
1978
|
+
/** POST /lead/create – create this lead */
|
|
1979
|
+
async createLead() {
|
|
1980
|
+
const payload = {
|
|
1981
|
+
email: self.email,
|
|
1982
|
+
name: self.name,
|
|
1983
|
+
phone: self.phone,
|
|
1984
|
+
companyKey: self.companyKey,
|
|
1985
|
+
source: self.source,
|
|
1986
|
+
leadType: self.leadType,
|
|
1987
|
+
referrerLink: self.referrerLink
|
|
1988
|
+
};
|
|
1989
|
+
const res = await reqPost("/lead/create", payload);
|
|
1990
|
+
if (res.status === "success" && res.data) {
|
|
1991
|
+
applySnapshot7(self, mapLeadFromApi(res.data));
|
|
1992
|
+
}
|
|
1993
|
+
return res;
|
|
1994
|
+
},
|
|
1995
|
+
/** POST /lead/update – update this lead */
|
|
1996
|
+
async updateLead() {
|
|
1997
|
+
if (!self.leadId || self.leadId === "new") {
|
|
1998
|
+
return { status: "failure", message: "leadId required" };
|
|
1999
|
+
}
|
|
2000
|
+
const payload = {
|
|
2001
|
+
leadId: self.leadId,
|
|
2002
|
+
email: self.email,
|
|
2003
|
+
name: self.name,
|
|
2004
|
+
phone: self.phone,
|
|
2005
|
+
companyKey: self.companyKey,
|
|
2006
|
+
source: self.source,
|
|
2007
|
+
leadType: self.leadType,
|
|
2008
|
+
referrerLink: self.referrerLink
|
|
2009
|
+
};
|
|
2010
|
+
const res = await reqPost("/lead/update", payload);
|
|
2011
|
+
if (res.status === "success" && res.data) {
|
|
2012
|
+
applySnapshot7(self, mapLeadFromApi(res.data));
|
|
2013
|
+
}
|
|
2014
|
+
return res;
|
|
2015
|
+
},
|
|
2016
|
+
/** GET /lead/delete – delete this lead by leadId */
|
|
2017
|
+
async deleteLead() {
|
|
2018
|
+
if (!self.leadId || self.leadId === "new") {
|
|
2019
|
+
return { status: "failure", message: "leadId required" };
|
|
2020
|
+
}
|
|
2021
|
+
return reqGet("/lead/delete", { lead_id: self.leadId });
|
|
2022
|
+
},
|
|
2023
|
+
/**
|
|
2024
|
+
* POST /lead/export/request – queue async full CSV export for self.companyKey (no list filters).
|
|
2025
|
+
* @param {object} [opts] – { notifyPath?, consumer? } consumer = Consumer header for completion webhook
|
|
2026
|
+
*/
|
|
2027
|
+
async requestLeadExport(opts = {}) {
|
|
2028
|
+
if (!self.companyKey || String(self.companyKey).trim() === "") {
|
|
2029
|
+
return { status: "failure", message: "companyKey required on model" };
|
|
2030
|
+
}
|
|
2031
|
+
return LeadModel.requestExport(self.companyKey, opts);
|
|
1962
2032
|
}
|
|
1963
2033
|
};
|
|
1964
2034
|
});
|
|
@@ -2013,6 +2083,42 @@ LeadModel.getByCompany = async (companyKey, opts = {}) => {
|
|
|
2013
2083
|
}
|
|
2014
2084
|
return null;
|
|
2015
2085
|
};
|
|
2086
|
+
LeadModel.createLead = async (payload) => {
|
|
2087
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
2088
|
+
const res = await reqPost("/lead/create", payload);
|
|
2089
|
+
if (res.status === "success" && res.data) {
|
|
2090
|
+
return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
|
|
2091
|
+
}
|
|
2092
|
+
return null;
|
|
2093
|
+
};
|
|
2094
|
+
LeadModel.updateLead = async (payload) => {
|
|
2095
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
2096
|
+
const res = await reqPost("/lead/update", payload);
|
|
2097
|
+
if (res.status === "success" && res.data) {
|
|
2098
|
+
return LeadModel.create(mapLeadFromApi(res.data), { env: getConfig() });
|
|
2099
|
+
}
|
|
2100
|
+
return null;
|
|
2101
|
+
};
|
|
2102
|
+
LeadModel.deleteLead = async (leadId) => {
|
|
2103
|
+
const { reqGet } = createRequestHelpersFromEnv(getConfig());
|
|
2104
|
+
return reqGet("/lead/delete", { lead_id: leadId });
|
|
2105
|
+
};
|
|
2106
|
+
LeadModel.requestExport = async (companyKey, opts = {}) => {
|
|
2107
|
+
const ck = companyKey != null ? String(companyKey).trim() : "";
|
|
2108
|
+
if (!ck) return { status: "failure", message: "companyKey required" };
|
|
2109
|
+
const { reqPost } = createRequestHelpersFromEnv(getConfig());
|
|
2110
|
+
const body = { company_key: ck };
|
|
2111
|
+
const np = opts.notifyPath ?? opts.notify_path;
|
|
2112
|
+
if (np != null && String(np).trim() !== "") {
|
|
2113
|
+
body.notify_path = String(np).trim();
|
|
2114
|
+
}
|
|
2115
|
+
const headers = {};
|
|
2116
|
+
const consumer = opts.consumer ?? opts.Consumer;
|
|
2117
|
+
if (consumer != null && String(consumer).trim() !== "") {
|
|
2118
|
+
headers.Consumer = String(consumer).trim();
|
|
2119
|
+
}
|
|
2120
|
+
return reqPost("/lead/export/request", body, void 0, { headers });
|
|
2121
|
+
};
|
|
2016
2122
|
LeadModel.getSources = async (companyKey) => {
|
|
2017
2123
|
var _a;
|
|
2018
2124
|
if (!companyKey || String(companyKey).trim() === "") return [];
|