@drawbridge/drawbridge-utils 0.0.66 → 0.0.67
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.cjs +0 -41
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +0 -40
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -48,7 +48,6 @@ __export(index_exports, {
|
|
|
48
48
|
megabyte: () => megabyte,
|
|
49
49
|
nanoid: () => nanoid,
|
|
50
50
|
percentage: () => percentage,
|
|
51
|
-
recordAction: () => recordAction,
|
|
52
51
|
reducers: () => reducers,
|
|
53
52
|
regex: () => regex,
|
|
54
53
|
shareUrls: () => shareUrls,
|
|
@@ -306,45 +305,6 @@ var incrementUsageTotals = async ({ controller, usageId, $inc, session }) => {
|
|
|
306
305
|
});
|
|
307
306
|
};
|
|
308
307
|
var isDuplicateKey = (error) => (error == null ? void 0 : error.code) === 11e3 || (error == null ? void 0 : error.code) === "11000" || /E11000|duplicate key/i.test((error == null ? void 0 : error.message) || "");
|
|
309
|
-
var recordAction = async ({ controller, organization, usageId, type, units = 1, key, meta = {}, traceId, session }) => {
|
|
310
|
-
if (!controller || !organization || !usageId || !type || !key) return;
|
|
311
|
-
const amount = Number(units);
|
|
312
|
-
if (!Number.isFinite(amount) || amount === 0) return;
|
|
313
|
-
let inserted = false;
|
|
314
|
-
try {
|
|
315
|
-
const { lastErrorObject } = await controller.update({
|
|
316
|
-
collection: "action",
|
|
317
|
-
data: {
|
|
318
|
-
$setOnInsert: {
|
|
319
|
-
organization,
|
|
320
|
-
usage: usageId,
|
|
321
|
-
type,
|
|
322
|
-
units: amount,
|
|
323
|
-
key,
|
|
324
|
-
meta,
|
|
325
|
-
...traceId && { traceId }
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
options: {
|
|
329
|
-
bypassDocumentValidation: true,
|
|
330
|
-
includeResultMetadata: true,
|
|
331
|
-
upsert: true,
|
|
332
|
-
...session && { session }
|
|
333
|
-
},
|
|
334
|
-
query: {
|
|
335
|
-
key,
|
|
336
|
-
usage: usageId
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
inserted = Boolean(lastErrorObject == null ? void 0 : lastErrorObject.upserted);
|
|
340
|
-
} catch (error) {
|
|
341
|
-
if (isDuplicateKey(error) && !session) return;
|
|
342
|
-
throw error;
|
|
343
|
-
}
|
|
344
|
-
if (inserted) {
|
|
345
|
-
await incrementUsageTotals({ controller, usageId, $inc: { "totals.actions": amount }, session });
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
308
|
|
|
349
309
|
// index.js
|
|
350
310
|
var nanoid = (0, import_nanoid.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 8);
|
|
@@ -532,7 +492,6 @@ var currency = (val) => (0, import_currency_codes.code)(val);
|
|
|
532
492
|
megabyte,
|
|
533
493
|
nanoid,
|
|
534
494
|
percentage,
|
|
535
|
-
recordAction,
|
|
536
495
|
reducers,
|
|
537
496
|
regex,
|
|
538
497
|
shareUrls,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { data, code } from 'currency-codes';
|
|
2
2
|
import { customAlphabet } from 'nanoid';
|
|
3
3
|
import { colorFormatted, colorAccessible } from './color.cjs';
|
|
4
|
-
export { incrementUsageTotals, isDuplicateKey
|
|
4
|
+
export { incrementUsageTotals, isDuplicateKey } from './usage.cjs';
|
|
5
5
|
import 'tinycolor2';
|
|
6
6
|
|
|
7
7
|
const font = {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { data, code } from 'currency-codes';
|
|
2
2
|
import { customAlphabet } from 'nanoid';
|
|
3
3
|
import { colorFormatted, colorAccessible } from './color.js';
|
|
4
|
-
export { incrementUsageTotals, isDuplicateKey
|
|
4
|
+
export { incrementUsageTotals, isDuplicateKey } from './usage.js';
|
|
5
5
|
import 'tinycolor2';
|
|
6
6
|
|
|
7
7
|
const font = {
|
package/dist/index.js
CHANGED
|
@@ -250,45 +250,6 @@ var incrementUsageTotals = async ({ controller, usageId, $inc, session }) => {
|
|
|
250
250
|
});
|
|
251
251
|
};
|
|
252
252
|
var isDuplicateKey = (error) => (error == null ? void 0 : error.code) === 11e3 || (error == null ? void 0 : error.code) === "11000" || /E11000|duplicate key/i.test((error == null ? void 0 : error.message) || "");
|
|
253
|
-
var recordAction = async ({ controller, organization, usageId, type, units = 1, key, meta = {}, traceId, session }) => {
|
|
254
|
-
if (!controller || !organization || !usageId || !type || !key) return;
|
|
255
|
-
const amount = Number(units);
|
|
256
|
-
if (!Number.isFinite(amount) || amount === 0) return;
|
|
257
|
-
let inserted = false;
|
|
258
|
-
try {
|
|
259
|
-
const { lastErrorObject } = await controller.update({
|
|
260
|
-
collection: "action",
|
|
261
|
-
data: {
|
|
262
|
-
$setOnInsert: {
|
|
263
|
-
organization,
|
|
264
|
-
usage: usageId,
|
|
265
|
-
type,
|
|
266
|
-
units: amount,
|
|
267
|
-
key,
|
|
268
|
-
meta,
|
|
269
|
-
...traceId && { traceId }
|
|
270
|
-
}
|
|
271
|
-
},
|
|
272
|
-
options: {
|
|
273
|
-
bypassDocumentValidation: true,
|
|
274
|
-
includeResultMetadata: true,
|
|
275
|
-
upsert: true,
|
|
276
|
-
...session && { session }
|
|
277
|
-
},
|
|
278
|
-
query: {
|
|
279
|
-
key,
|
|
280
|
-
usage: usageId
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
inserted = Boolean(lastErrorObject == null ? void 0 : lastErrorObject.upserted);
|
|
284
|
-
} catch (error) {
|
|
285
|
-
if (isDuplicateKey(error) && !session) return;
|
|
286
|
-
throw error;
|
|
287
|
-
}
|
|
288
|
-
if (inserted) {
|
|
289
|
-
await incrementUsageTotals({ controller, usageId, $inc: { "totals.actions": amount }, session });
|
|
290
|
-
}
|
|
291
|
-
};
|
|
292
253
|
|
|
293
254
|
// index.js
|
|
294
255
|
var nanoid = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 8);
|
|
@@ -475,7 +436,6 @@ export {
|
|
|
475
436
|
megabyte,
|
|
476
437
|
nanoid,
|
|
477
438
|
percentage,
|
|
478
|
-
recordAction,
|
|
479
439
|
reducers,
|
|
480
440
|
regex,
|
|
481
441
|
shareUrls,
|
package/package.json
CHANGED