MCPcopy Create free account
hub / github.com/firebase/firebase-tools / constructHttpsFunc

Method constructHttpsFunc

src/localFunction.ts:62–122  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60 }
61
62 private constructHttpsFunc(): requestShim {
63 if (!this.url) {
64 throw new Error("No URL provided");
65 }
66 const callClient = new Client({ urlPrefix: this.url, auth: false });
67 type verbFn = (...args: any) => Promise<string>;
68 const verbFactory = (
69 hasRequestBody: boolean,
70 method: (
71 path: string,
72 bodyOrOpts?: any,
73 opts?: ClientVerbOptions,
74 ) => Promise<ClientResponse<any>>,
75 ): verbFn => {
76 return async (pathOrOptions?: string | HttpsOptions, options?: HttpsOptions) => {
77 const { path, opts } = this.extractArgs(pathOrOptions, options);
78 try {
79 const res = hasRequestBody
80 ? await method(path, opts.body, toClientVerbOptions(opts))
81 : await method(path, toClientVerbOptions(opts));
82 this.requestCallBack(undefined, res, res.body);
83 } catch (err) {
84 this.requestCallBack(err);
85 }
86 return HTTPS_SENTINEL;
87 };
88 };
89
90 const shim = verbFactory(true, (path: string, json?: any, opts?: ClientVerbOptions) => {
91 const req = Object.assign(opts || {}, {
92 path: path,
93 body: json,
94 method: opts?.method || "GET",
95 });
96 return callClient.request(req);
97 });
98 const verbs: verbMethods = {
99 post: verbFactory(true, (path: string, json?: any, opts?: ClientVerbOptions) =>
100 callClient.post(path, json, opts),
101 ),
102 put: verbFactory(true, (path: string, json?: any, opts?: ClientVerbOptions) =>
103 callClient.put(path, json, opts),
104 ),
105 patch: verbFactory(true, (path: string, json?: any, opts?: ClientVerbOptions) =>
106 callClient.patch(path, json, opts),
107 ),
108 get: verbFactory(false, (path: string, opts?: ClientVerbOptions) =>
109 callClient.get(path, opts),
110 ),
111 del: verbFactory(false, (path: string, opts?: ClientVerbOptions) =>
112 callClient.delete(path, opts),
113 ),
114 delete: verbFactory(false, (path: string, opts?: ClientVerbOptions) =>
115 callClient.delete(path, opts),
116 ),
117 options: verbFactory(false, (path: string, opts?: ClientVerbOptions) =>
118 callClient.options(path, opts),
119 ),

Callers 1

makeFnMethod · 0.95

Calls 7

requestMethod · 0.95
postMethod · 0.95
putMethod · 0.95
patchMethod · 0.95
getMethod · 0.95
deleteMethod · 0.95
optionsMethod · 0.95

Tested by

no test coverage detected