Skip to content

Commit 4e24f8e

Browse files
authored
www: fix upcoming invoice & update pricing lookup key (#2265)
* www: fix upcoming invoice * update * update * update * prettier * try catch
1 parent d330720 commit 4e24f8e

File tree

203 files changed

+1412
-1333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+1412
-1333
lines changed

packages/api/src/app-router.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function initDb(params: CliArgs, serviceName = "api") {
8080
...pgBaseParams,
8181
poolMaxSize: pgJobsPoolSize,
8282
appName: `${appName}-jobs`,
83-
}
83+
},
8484
);
8585
return { db, jobsDb, store };
8686
}
@@ -111,7 +111,7 @@ export async function initClients(params: CliArgs, serviceName = "api") {
111111

112112
if (!stripeSecretKey) {
113113
console.warn(
114-
"Warning: Missing Stripe API key. In development, make sure to configure one in .env.local file."
114+
"Warning: Missing Stripe API key. In development, make sure to configure one in .env.local file.",
115115
);
116116
}
117117
const stripe = stripeSecretKey
@@ -155,7 +155,7 @@ export default async function appRouter(params: CliArgs) {
155155
if (supportAddr || sendgridTemplateId || sendgridApiKey) {
156156
if (!(supportAddr && sendgridTemplateId && sendgridApiKey)) {
157157
throw new Error(
158-
`Sending emails requires supportAddr, sendgridTemplateId, and sendgridApiKey`
158+
`Sending emails requires supportAddr, sendgridTemplateId, and sendgridApiKey`,
159159
);
160160
}
161161
}
@@ -220,7 +220,7 @@ export default async function appRouter(params: CliArgs) {
220220
exposedHeaders: ["*"],
221221
},
222222
},
223-
})
223+
}),
224224
);
225225

226226
// stripe webhook requires raw body
@@ -241,7 +241,7 @@ export default async function appRouter(params: CliArgs) {
241241
if (returnRegionInOrchestrator) {
242242
app.use((req, res, next) => {
243243
req.orchestratorsGetters.push(() =>
244-
regionsGetter(halfRegionOrchestratorsUntrusted)
244+
regionsGetter(halfRegionOrchestratorsUntrusted),
245245
);
246246
return next();
247247
});
@@ -251,7 +251,7 @@ export default async function appRouter(params: CliArgs) {
251251
app.use(
252252
subgraph({
253253
subgraphUrl,
254-
})
254+
}),
255255
);
256256
}
257257

@@ -261,7 +261,7 @@ export default async function appRouter(params: CliArgs) {
261261
prefixRouter.get(
262262
"/stream/:streamId/broadcaster",
263263
geolocateMiddleware({}),
264-
getBroadcasterHandler
264+
getBroadcasterHandler,
265265
);
266266
for (const [name, controller] of Object.entries(controllers)) {
267267
// if we're operating in api-region mode, only handle geolocation traffic, forward the rest on

packages/api/src/app/stream-info/parse-cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function parseCli() {
1212
1313
Options my also be provided as LP_API_ prefixed environment variables, e.g. LP_API_PORT=5000 is the same as --port=5000.
1414
15-
`
15+
`,
1616
)
1717
.env("LP_API_")
1818
//.strict(true)

packages/api/src/app/stream-info/stream-info-app.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class statusPoller {
200200

201201
if (si.stream?.id !== getStreamId(mid)) {
202202
console.log(
203-
`stream id changed from ${si.stream?.id} to ${getStreamId(mid)}`
203+
`stream id changed from ${si.stream?.id} to ${getStreamId(mid)}`,
204204
);
205205
// save the old stream info so it's properly housekept later
206206
this.seenStreams.set(`old_${mid}_${si.stream?.id}`, si);
@@ -266,7 +266,7 @@ class statusPoller {
266266

267267
private async housekeepSeenStreams(
268268
activeStreams?: MasterPlaylistDictionary,
269-
force?: boolean
269+
force?: boolean,
270270
) {
271271
for (const [mid, si] of this.seenStreams) {
272272
if (activeStreams && mid in activeStreams) {
@@ -395,7 +395,7 @@ export default async function makeApp(params: CliArgs) {
395395
.listen(port, () => {
396396
listenPort = listener.address().port;
397397
logger.info(
398-
`Stream info server listening on http://0.0.0.0:${listenPort}`
398+
`Stream info server listening on http://0.0.0.0:${listenPort}`,
399399
);
400400
resolve();
401401
})

packages/api/src/compile-schemas.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ fs.ensureDirSync(schemaDistDir);
3131

3232
const apiSchemaStr = fs.readFileSync(
3333
path.resolve(schemaDir, "api-schema.yaml"),
34-
"utf8"
34+
"utf8",
3535
);
3636
const dbSchemaStr = fs.readFileSync(
3737
path.resolve(schemaDir, "db-schema.yaml"),
38-
"utf8"
38+
"utf8",
3939
);
4040
const apiData = parseYaml(apiSchemaStr);
4141
const dbData = parseYaml(dbSchemaStr);

packages/api/src/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const products = {
158158
pay_as_you_go_1: {
159159
order: 6,
160160
name: "Pay-As-You-Go",
161-
lookupKeys: ["transcoding_usage", "tstreaming_usage", "tstorage_usage"],
161+
lookupKeys: ["transcoding_usage", "tstreaming_usage", "tstorage_usage2"],
162162
usage: [
163163
{
164164
name: "Transcoding",
@@ -290,7 +290,7 @@ export const products = {
290290
prod_O9XuWMU1Up6QKf: {
291291
order: 11,
292292
name: "Pay-As-You-Go",
293-
lookupKeys: ["transcoding_usage", "tstreaming_usage", "tstorage_usage"],
293+
lookupKeys: ["transcoding_usage", "tstreaming_usage", "tstorage_usage2"],
294294
usage: [
295295
{
296296
name: "Transcoding",

packages/api/src/controllers/access-control.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ describe("controllers/access-control", () => {
323323
expect(res3.status).toBe(403);
324324
let resJson = await res3.json();
325325
expect(resJson.errors[0]).toBe(
326-
`Content is gated and origin not in allowed origins`
326+
`Content is gated and origin not in allowed origins`,
327327
);
328328
const res4 = await client.post("/access-control/gate", {
329329
stream: `video+${gatedAsset.playbackId}`,
@@ -338,7 +338,7 @@ describe("controllers/access-control", () => {
338338
expect(res4.status).toBe(403);
339339
let resJson2 = await res4.json();
340340
expect(resJson2.errors[0]).toBe(
341-
"Content is gated and corresponding public key not found"
341+
"Content is gated and corresponding public key not found",
342342
);
343343
});
344344

packages/api/src/controllers/access-control.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type GateConfig = {
4242
async function fireGateWebhook(
4343
webhook: DBWebhook,
4444
content: DBStream | WithID<Asset>,
45-
payload: AccessControlGatePayload
45+
payload: AccessControlGatePayload,
4646
) {
4747
let timestamp = Date.now();
4848
let jsonPayload = {
@@ -75,7 +75,7 @@ async function fireGateWebhook(
7575
const sigHeaders = signatureHeaders(
7676
params.body,
7777
webhook.sharedSecret,
78-
timestamp
78+
timestamp,
7979
);
8080
params.headers = { ...params.headers, ...sigHeaders };
8181

@@ -113,7 +113,7 @@ async function fireGateWebhook(
113113
timestamp,
114114
statusCode,
115115
errorMessage,
116-
undefined
116+
undefined,
117117
);
118118
}
119119
if ("pull" in content && content.pull) {
@@ -129,26 +129,26 @@ async function fireGateWebhook(
129129
`access-control: gate: webhook=${
130130
webhook.id
131131
} statusCode=${statusCode} respSpanId=${resp?.headers.get(
132-
"X-Tlive-Spanid"
132+
"X-Tlive-Spanid",
133133
)} respBody=${Buffer.from(respBody).toString("base64")} duration=${
134134
process.hrtime(startTime)[1] / 1e6
135135
}ms accessKey=${payload.accessKey} playbackId=${
136136
content.playbackId
137137
} webhook=${
138138
webhook.id
139-
} referer=${referer} origin=${origin} playURL=${playURL} playDomain=${playDomain}`
139+
} referer=${referer} origin=${origin} playURL=${playURL} playDomain=${playDomain}`,
140140
);
141141
} catch (e) {
142142
console.log(
143143
`access-control: gate: webhook=${
144144
webhook.id
145145
} statusCode=${statusCode} respSpanId=${resp?.headers.get(
146-
"X-Tlive-Spanid"
146+
"X-Tlive-Spanid",
147147
)} respBody=${Buffer.from(respBody).toString("base64")} duration=${
148148
process.hrtime(startTime)[1] / 1e6
149149
}ms accessKey=${payload.accessKey} playbackId=${
150150
content.playbackId
151-
} webhook=${webhook.id}`
151+
} webhook=${webhook.id}`,
152152
);
153153
}
154154
} else {
@@ -157,7 +157,7 @@ async function fireGateWebhook(
157157
webhook.id
158158
} statusCode=${statusCode} duration=${
159159
process.hrtime(startTime)[1] / 1e6
160-
}ms`
160+
}ms`,
161161
);
162162
}
163163
return statusCode;
@@ -172,7 +172,7 @@ function checkRespBody(resp: string): number | null {
172172
return body.ret;
173173
} catch (e) {
174174
console.log(
175-
`access-control: error checking response body for status code: ${e}`
175+
`access-control: error checking response body for status code: ${e}`,
176176
);
177177
}
178178
}
@@ -192,7 +192,7 @@ app.post(
192192
(await db.stream.getByPlaybackId(playbackId)) ||
193193
(await db.asset.getByPlaybackId(playbackId))
194194
);
195-
}
195+
},
196196
);
197197

198198
res.set("Cache-Control", "max-age=120,stale-while-revalidate=600");
@@ -261,7 +261,7 @@ app.post(
261261
if (origin === "null" || origin === "") {
262262
origin = referer;
263263
console.log(
264-
`access-control: gate: origin is null, using referer=${origin} for playbackId=${playbackId}`
264+
`access-control: gate: origin is null, using referer=${origin} for playbackId=${playbackId}`,
265265
);
266266
}
267267

@@ -279,7 +279,7 @@ app.post(
279279
access-control: gate: content with playbackId=${playbackId} is gated but origin=${origin} not in allowed origins=${allowedOrigins}, disallowing playback
280280
`);
281281
throw new ForbiddenError(
282-
`Content is gated and origin not in allowed origins`
282+
`Content is gated and origin not in allowed origins`,
283283
);
284284
}
285285
}
@@ -296,7 +296,7 @@ app.post(
296296
access-control: gate: no pub provided for playbackId=${playbackId}, disallowing playback
297297
`);
298298
throw new ForbiddenError(
299-
"Content is gated and requires a public key"
299+
"Content is gated and requires a public key",
300300
);
301301
}
302302

@@ -307,15 +307,15 @@ app.post(
307307
sql`signing_key.data->>'publicKey' = ${req.body.pub}`,
308308
];
309309
return db.signingKey.find(query, { limit: 2 });
310-
}
310+
},
311311
);
312312

313313
if (signingKeyOutput.length == 0) {
314314
console.log(`
315315
access-control: gate: content with playbackId=${playbackId} is gated but corresponding public key not found for key=${req.body.pub}, disallowing playback
316316
`);
317317
throw new ForbiddenError(
318-
"Content is gated and corresponding public key not found"
318+
"Content is gated and corresponding public key not found",
319319
);
320320
}
321321

@@ -325,7 +325,7 @@ app.post(
325325
access-control: gate: content contentId=${content.id} with playbackId=${playbackId} is gated but multiple (${signingKeyOutput.length}) public keys found for key=${req.body.pub}, disallowing playback, colliding keys=${collisionKeys}
326326
`);
327327
throw new BadRequestError(
328-
"Multiple signing keys found for the same public key."
328+
"Multiple signing keys found for the same public key.",
329329
);
330330
}
331331

@@ -352,7 +352,7 @@ app.post(
352352
case "webhook":
353353
if (!req.body.accessKey || req.body.type !== "accessKey") {
354354
throw new ForbiddenError(
355-
"Content is gated and requires an access key"
355+
"Content is gated and requires an access key",
356356
);
357357
}
358358
const webhook = await db.webhook.get(content.playbackPolicy.webhookId, {
@@ -363,7 +363,7 @@ app.post(
363363
access-control: gate: content with playbackId=${playbackId} is gated but corresponding webhook not found for webhookId=${content.playbackPolicy.webhookId}, disallowing playback
364364
`);
365365
throw new InternalServerError(
366-
"Content is gated and corresponding webhook not found"
366+
"Content is gated and corresponding webhook not found",
367367
);
368368
}
369369

@@ -379,22 +379,22 @@ app.post(
379379
access-control: gate: content with playbackId=${playbackId} is gated but webhook=${webhook.id} failed, disallowing playback
380380
`);
381381
throw new BadGatewayError(
382-
"Content is gated and corresponding webhook failed"
382+
"Content is gated and corresponding webhook failed",
383383
);
384384
} else {
385385
console.log(`
386386
access-control: gate: content with playbackId=${playbackId} is gated but webhook=${webhook.id} returned status code ${statusCode}, disallowing playback
387387
`);
388388
throw new ForbiddenError(
389-
"Content is gated and corresponding webhook failed"
389+
"Content is gated and corresponding webhook failed",
390390
);
391391
}
392392
default:
393393
throw new BadRequestError(
394-
`unknown playbackPolicy type: ${playbackPolicyType}`
394+
`unknown playbackPolicy type: ${playbackPolicyType}`,
395395
);
396396
}
397-
}
397+
},
398398
);
399399

400400
app.get("/public-key", async (req, res) => {
@@ -414,7 +414,7 @@ app.get("/public-key", async (req, res) => {
414414
return response.json();
415415
} else {
416416
throw new Error(
417-
`access-control: error retrieving public key from catalyst statusCode=${response.status} catalystUrl=${url}`
417+
`access-control: error retrieving public key from catalyst statusCode=${response.status} catalystUrl=${url}`,
418418
);
419419
}
420420
})

packages/api/src/controllers/admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ app.post(
117117
i++;
118118
}
119119
res.end(`cleaned routes for ${cleaned}/${toClean.length} streams\n`);
120-
}
120+
},
121121
);
122122

123123
app.post("/active-clean", authorizer({ anyAdmin: true }), async (req, res) => {

packages/api/src/controllers/api-token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ app.get("/", async (req, res) => {
116116
query.push(
117117
sql`coalesce(api_token.data->>'projectId', ${
118118
req.user.defaultProjectId || ""
119-
}) = ${req.project?.id || ""}`
119+
}) = ${req.project?.id || ""}`,
120120
);
121121
}
122122

packages/api/src/controllers/api-token.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("controllers/api-token", () => {
6363

6464
const nonAdminUserRes = await server.store.get(
6565
`user/${nonAdminUser.id}`,
66-
false
66+
false,
6767
);
6868
nonAdminUser = { ...nonAdminUserRes, emailValid: true };
6969
await server.store.replace(nonAdminUser);

0 commit comments

Comments
 (0)