@drawbridge/drawbridge-utils 0.0.25 → 0.0.27
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/cdn.d.cts +1 -1
- package/dist/cdn.d.ts +1 -1
- package/dist/index.cjs +26 -5
- package/dist/index.d.cts +44 -6
- package/dist/index.d.ts +44 -6
- package/dist/index.js +25 -5
- package/dist/shopify.cjs +2 -1
- package/dist/shopify.d.cts +1 -1
- package/dist/shopify.d.ts +1 -1
- package/dist/shopify.js +2 -1
- package/package.json +3 -2
package/dist/cdn.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Build a DigitalOcean Spaces CDN URL with a cache-busting query string.
|
|
2
2
|
// `asset` is any object with a `sizes` map. `size` is the sizes key (e.g.
|
|
3
|
-
// '100x100', 'original', '
|
|
3
|
+
// '100x100', 'original', 'hls'). `timestamp` is required — without it the
|
|
4
4
|
// URL would never change across uploads and the CDN/browser would serve a
|
|
5
5
|
// stale asset. Pass the asset's own `updatedAt` when it has one, or the
|
|
6
6
|
// parent document's `updatedAt` for embedded assets like `user.image`.
|
package/dist/cdn.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Build a DigitalOcean Spaces CDN URL with a cache-busting query string.
|
|
2
2
|
// `asset` is any object with a `sizes` map. `size` is the sizes key (e.g.
|
|
3
|
-
// '100x100', 'original', '
|
|
3
|
+
// '100x100', 'original', 'hls'). `timestamp` is required — without it the
|
|
4
4
|
// URL would never change across uploads and the CDN/browser would serve a
|
|
5
5
|
// stale asset. Pass the asset's own `updatedAt` when it has one, or the
|
|
6
6
|
// parent document's `updatedAt` for embedded assets like `user.image`.
|
package/dist/index.cjs
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
formatNumber: () => formatNumber,
|
|
32
32
|
getPlanFeature: () => getPlanFeature,
|
|
33
33
|
gigabyte: () => gigabyte,
|
|
34
|
+
incrementUsageTotals: () => incrementUsageTotals,
|
|
34
35
|
infinite: () => infinite,
|
|
35
36
|
isInfinite: () => isInfinite,
|
|
36
37
|
megabyte: () => megabyte,
|
|
@@ -52,11 +53,6 @@ var font = {
|
|
|
52
53
|
weight: "regular"
|
|
53
54
|
};
|
|
54
55
|
var constants_default = {
|
|
55
|
-
action: {
|
|
56
|
-
usage: {
|
|
57
|
-
actions: 0
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
56
|
brand: {
|
|
61
57
|
style: {
|
|
62
58
|
body: font,
|
|
@@ -179,6 +175,11 @@ var constants_default = {
|
|
|
179
175
|
users: 0
|
|
180
176
|
}
|
|
181
177
|
},
|
|
178
|
+
step: {
|
|
179
|
+
usage: {
|
|
180
|
+
actions: 0
|
|
181
|
+
}
|
|
182
|
+
},
|
|
182
183
|
template: {
|
|
183
184
|
page: {
|
|
184
185
|
style: {
|
|
@@ -309,6 +310,25 @@ var getPlanFeature = (plan, key) => {
|
|
|
309
310
|
message: granted ? feature : error
|
|
310
311
|
};
|
|
311
312
|
};
|
|
313
|
+
var incrementUsageTotals = async ({ controller, usageId, $inc, session }) => {
|
|
314
|
+
if (!usageId || !$inc) return;
|
|
315
|
+
const safeInc = Object.fromEntries(
|
|
316
|
+
Object.entries($inc).filter(([, value]) => {
|
|
317
|
+
const number = Number(value);
|
|
318
|
+
return Number.isFinite(number) && number !== 0;
|
|
319
|
+
})
|
|
320
|
+
);
|
|
321
|
+
if (Object.keys(safeInc).length === 0) return;
|
|
322
|
+
return controller.update({
|
|
323
|
+
collection: "usage",
|
|
324
|
+
data: { $inc: safeInc },
|
|
325
|
+
options: {
|
|
326
|
+
bypassDocumentValidation: true,
|
|
327
|
+
...session && { session }
|
|
328
|
+
},
|
|
329
|
+
query: { id: usageId }
|
|
330
|
+
});
|
|
331
|
+
};
|
|
312
332
|
var percentage = (value1, value2, decimals = 1) => ((value1 || 0) / (value2 || 0) * 100 || 0).toFixed(decimals);
|
|
313
333
|
var reducers = {
|
|
314
334
|
fields: (data2 = [], callback = () => ({})) => data2.reduce(
|
|
@@ -400,6 +420,7 @@ var currency = (val) => (0, import_currency_codes.code)(val);
|
|
|
400
420
|
formatNumber,
|
|
401
421
|
getPlanFeature,
|
|
402
422
|
gigabyte,
|
|
423
|
+
incrementUsageTotals,
|
|
403
424
|
infinite,
|
|
404
425
|
isInfinite,
|
|
405
426
|
megabyte,
|
package/dist/index.d.cts
CHANGED
|
@@ -8,11 +8,6 @@ const font = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
var constantsData = {
|
|
11
|
-
action : {
|
|
12
|
-
usage : {
|
|
13
|
-
actions : 0
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
11
|
brand : {
|
|
17
12
|
style : {
|
|
18
13
|
body : font,
|
|
@@ -135,6 +130,11 @@ var constantsData = {
|
|
|
135
130
|
users : 0
|
|
136
131
|
}
|
|
137
132
|
},
|
|
133
|
+
step : {
|
|
134
|
+
usage : {
|
|
135
|
+
actions : 0
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
138
|
template : {
|
|
139
139
|
page : {
|
|
140
140
|
style : {
|
|
@@ -313,6 +313,44 @@ const getPlanFeature = ( plan, key ) => {
|
|
|
313
313
|
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
+
// Centralized $inc helper for the per-org usage doc. Replaces inline
|
|
317
|
+
// $inc-with-bypass-validation patterns in drawbridge-api + drawbridge-sync.
|
|
318
|
+
//
|
|
319
|
+
// MongoDB's $inc with 0 / NaN / undefined / null writes the value into the
|
|
320
|
+
// field (zeroing or NaN-ing it) instead of no-op'ing — so we filter the
|
|
321
|
+
// $inc object to keep only finite, non-zero values and callers don't have
|
|
322
|
+
// to remember the guard.
|
|
323
|
+
//
|
|
324
|
+
// `session` is forwarded when present so callers inside a transaction get
|
|
325
|
+
// atomic writes; standalone callers omit it.
|
|
326
|
+
const incrementUsageTotals = async ({ controller, usageId, $inc, session }) => {
|
|
327
|
+
|
|
328
|
+
if( ! usageId || ! $inc ) return;
|
|
329
|
+
|
|
330
|
+
const safeInc = Object.fromEntries(
|
|
331
|
+
Object.entries( $inc ).filter( ([ , value ]) => {
|
|
332
|
+
|
|
333
|
+
const number = Number( value );
|
|
334
|
+
|
|
335
|
+
return Number.isFinite( number ) && number !== 0;
|
|
336
|
+
|
|
337
|
+
})
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
if( Object.keys( safeInc ).length === 0 ) return;
|
|
341
|
+
|
|
342
|
+
return controller.update({
|
|
343
|
+
collection : 'usage',
|
|
344
|
+
data : { $inc : safeInc },
|
|
345
|
+
options : {
|
|
346
|
+
bypassDocumentValidation : true,
|
|
347
|
+
...( session && { session })
|
|
348
|
+
},
|
|
349
|
+
query : { id : usageId }
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
};
|
|
353
|
+
|
|
316
354
|
const percentage = ( value1, value2, decimals = 1 ) => ( ( ( ( value1 || 0 ) / ( value2 || 0 ) ) * 100 ) || 0 ).toFixed( decimals );
|
|
317
355
|
|
|
318
356
|
const reducers = {
|
|
@@ -411,4 +449,4 @@ const currencies = data.map( ( item ) => ({
|
|
|
411
449
|
|
|
412
450
|
const currency = ( val ) => code( val );
|
|
413
451
|
|
|
414
|
-
export { bytesToGB, bytesToMB, capitalize, constants, currencies, currency, expiredPaymentMethod, formatCurrency, formatDateString, formatNumber, getPlanFeature, gigabyte, infinite, isInfinite, megabyte, nanoid, percentage, reducers, regex, shareUrls, urlRoot };
|
|
452
|
+
export { bytesToGB, bytesToMB, capitalize, constants, currencies, currency, expiredPaymentMethod, formatCurrency, formatDateString, formatNumber, getPlanFeature, gigabyte, incrementUsageTotals, infinite, isInfinite, megabyte, nanoid, percentage, reducers, regex, shareUrls, urlRoot };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,11 +8,6 @@ const font = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
var constantsData = {
|
|
11
|
-
action : {
|
|
12
|
-
usage : {
|
|
13
|
-
actions : 0
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
11
|
brand : {
|
|
17
12
|
style : {
|
|
18
13
|
body : font,
|
|
@@ -135,6 +130,11 @@ var constantsData = {
|
|
|
135
130
|
users : 0
|
|
136
131
|
}
|
|
137
132
|
},
|
|
133
|
+
step : {
|
|
134
|
+
usage : {
|
|
135
|
+
actions : 0
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
138
|
template : {
|
|
139
139
|
page : {
|
|
140
140
|
style : {
|
|
@@ -313,6 +313,44 @@ const getPlanFeature = ( plan, key ) => {
|
|
|
313
313
|
|
|
314
314
|
};
|
|
315
315
|
|
|
316
|
+
// Centralized $inc helper for the per-org usage doc. Replaces inline
|
|
317
|
+
// $inc-with-bypass-validation patterns in drawbridge-api + drawbridge-sync.
|
|
318
|
+
//
|
|
319
|
+
// MongoDB's $inc with 0 / NaN / undefined / null writes the value into the
|
|
320
|
+
// field (zeroing or NaN-ing it) instead of no-op'ing — so we filter the
|
|
321
|
+
// $inc object to keep only finite, non-zero values and callers don't have
|
|
322
|
+
// to remember the guard.
|
|
323
|
+
//
|
|
324
|
+
// `session` is forwarded when present so callers inside a transaction get
|
|
325
|
+
// atomic writes; standalone callers omit it.
|
|
326
|
+
const incrementUsageTotals = async ({ controller, usageId, $inc, session }) => {
|
|
327
|
+
|
|
328
|
+
if( ! usageId || ! $inc ) return;
|
|
329
|
+
|
|
330
|
+
const safeInc = Object.fromEntries(
|
|
331
|
+
Object.entries( $inc ).filter( ([ , value ]) => {
|
|
332
|
+
|
|
333
|
+
const number = Number( value );
|
|
334
|
+
|
|
335
|
+
return Number.isFinite( number ) && number !== 0;
|
|
336
|
+
|
|
337
|
+
})
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
if( Object.keys( safeInc ).length === 0 ) return;
|
|
341
|
+
|
|
342
|
+
return controller.update({
|
|
343
|
+
collection : 'usage',
|
|
344
|
+
data : { $inc : safeInc },
|
|
345
|
+
options : {
|
|
346
|
+
bypassDocumentValidation : true,
|
|
347
|
+
...( session && { session })
|
|
348
|
+
},
|
|
349
|
+
query : { id : usageId }
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
};
|
|
353
|
+
|
|
316
354
|
const percentage = ( value1, value2, decimals = 1 ) => ( ( ( ( value1 || 0 ) / ( value2 || 0 ) ) * 100 ) || 0 ).toFixed( decimals );
|
|
317
355
|
|
|
318
356
|
const reducers = {
|
|
@@ -411,4 +449,4 @@ const currencies = data.map( ( item ) => ({
|
|
|
411
449
|
|
|
412
450
|
const currency = ( val ) => code( val );
|
|
413
451
|
|
|
414
|
-
export { bytesToGB, bytesToMB, capitalize, constants, currencies, currency, expiredPaymentMethod, formatCurrency, formatDateString, formatNumber, getPlanFeature, gigabyte, infinite, isInfinite, megabyte, nanoid, percentage, reducers, regex, shareUrls, urlRoot };
|
|
452
|
+
export { bytesToGB, bytesToMB, capitalize, constants, currencies, currency, expiredPaymentMethod, formatCurrency, formatDateString, formatNumber, getPlanFeature, gigabyte, incrementUsageTotals, infinite, isInfinite, megabyte, nanoid, percentage, reducers, regex, shareUrls, urlRoot };
|
package/dist/index.js
CHANGED
|
@@ -9,11 +9,6 @@ var font = {
|
|
|
9
9
|
weight: "regular"
|
|
10
10
|
};
|
|
11
11
|
var constants_default = {
|
|
12
|
-
action: {
|
|
13
|
-
usage: {
|
|
14
|
-
actions: 0
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
12
|
brand: {
|
|
18
13
|
style: {
|
|
19
14
|
body: font,
|
|
@@ -136,6 +131,11 @@ var constants_default = {
|
|
|
136
131
|
users: 0
|
|
137
132
|
}
|
|
138
133
|
},
|
|
134
|
+
step: {
|
|
135
|
+
usage: {
|
|
136
|
+
actions: 0
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
139
|
template: {
|
|
140
140
|
page: {
|
|
141
141
|
style: {
|
|
@@ -266,6 +266,25 @@ var getPlanFeature = (plan, key) => {
|
|
|
266
266
|
message: granted ? feature : error
|
|
267
267
|
};
|
|
268
268
|
};
|
|
269
|
+
var incrementUsageTotals = async ({ controller, usageId, $inc, session }) => {
|
|
270
|
+
if (!usageId || !$inc) return;
|
|
271
|
+
const safeInc = Object.fromEntries(
|
|
272
|
+
Object.entries($inc).filter(([, value]) => {
|
|
273
|
+
const number = Number(value);
|
|
274
|
+
return Number.isFinite(number) && number !== 0;
|
|
275
|
+
})
|
|
276
|
+
);
|
|
277
|
+
if (Object.keys(safeInc).length === 0) return;
|
|
278
|
+
return controller.update({
|
|
279
|
+
collection: "usage",
|
|
280
|
+
data: { $inc: safeInc },
|
|
281
|
+
options: {
|
|
282
|
+
bypassDocumentValidation: true,
|
|
283
|
+
...session && { session }
|
|
284
|
+
},
|
|
285
|
+
query: { id: usageId }
|
|
286
|
+
});
|
|
287
|
+
};
|
|
269
288
|
var percentage = (value1, value2, decimals = 1) => ((value1 || 0) / (value2 || 0) * 100 || 0).toFixed(decimals);
|
|
270
289
|
var reducers = {
|
|
271
290
|
fields: (data2 = [], callback = () => ({})) => data2.reduce(
|
|
@@ -356,6 +375,7 @@ export {
|
|
|
356
375
|
formatNumber,
|
|
357
376
|
getPlanFeature,
|
|
358
377
|
gigabyte,
|
|
378
|
+
incrementUsageTotals,
|
|
359
379
|
infinite,
|
|
360
380
|
isInfinite,
|
|
361
381
|
megabyte,
|
package/dist/shopify.cjs
CHANGED
|
@@ -175,6 +175,7 @@ var resolveConnectionSettings = async ({ connection, controller }) => {
|
|
|
175
175
|
};
|
|
176
176
|
};
|
|
177
177
|
var refreshAdminToken = async ({ connection, controller }) => {
|
|
178
|
+
var _a;
|
|
178
179
|
const credential = await controller.get({
|
|
179
180
|
collection: "credential",
|
|
180
181
|
query: {
|
|
@@ -186,7 +187,7 @@ var refreshAdminToken = async ({ connection, controller }) => {
|
|
|
186
187
|
}
|
|
187
188
|
;
|
|
188
189
|
const settings = decrypt(credential.settings);
|
|
189
|
-
const
|
|
190
|
+
const domain = (_a = credential.provider) == null ? void 0 : _a.id;
|
|
190
191
|
const { refreshToken } = settings;
|
|
191
192
|
const data = await shopifyOAuthFetch(
|
|
192
193
|
`https://${domain}/admin/oauth/access_token`,
|
package/dist/shopify.d.cts
CHANGED
|
@@ -186,7 +186,7 @@ const refreshAdminToken = async ({ connection, controller }) => {
|
|
|
186
186
|
|
|
187
187
|
}
|
|
188
188
|
const settings = decrypt( credential.settings );
|
|
189
|
-
const
|
|
189
|
+
const domain = credential.provider?.id;
|
|
190
190
|
const { refreshToken } = settings;
|
|
191
191
|
|
|
192
192
|
const data = await shopifyOAuthFetch(
|
package/dist/shopify.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ const refreshAdminToken = async ({ connection, controller }) => {
|
|
|
186
186
|
|
|
187
187
|
}
|
|
188
188
|
const settings = decrypt( credential.settings );
|
|
189
|
-
const
|
|
189
|
+
const domain = credential.provider?.id;
|
|
190
190
|
const { refreshToken } = settings;
|
|
191
191
|
|
|
192
192
|
const data = await shopifyOAuthFetch(
|
package/dist/shopify.js
CHANGED
|
@@ -101,6 +101,7 @@ var resolveConnectionSettings = async ({ connection, controller }) => {
|
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
103
|
var refreshAdminToken = async ({ connection, controller }) => {
|
|
104
|
+
var _a;
|
|
104
105
|
const credential = await controller.get({
|
|
105
106
|
collection: "credential",
|
|
106
107
|
query: {
|
|
@@ -112,7 +113,7 @@ var refreshAdminToken = async ({ connection, controller }) => {
|
|
|
112
113
|
}
|
|
113
114
|
;
|
|
114
115
|
const settings = decrypt(credential.settings);
|
|
115
|
-
const
|
|
116
|
+
const domain = (_a = credential.provider) == null ? void 0 : _a.id;
|
|
116
117
|
const { refreshToken } = settings;
|
|
117
118
|
const data = await shopifyOAuthFetch(
|
|
118
119
|
`https://${domain}/admin/oauth/access_token`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"dependencies": {
|
|
4
|
+
"@drawbridge/drawbridge-agents": "0.0.10",
|
|
4
5
|
"axios": "1.16.0",
|
|
5
6
|
"currency-codes": "2.2.0",
|
|
6
7
|
"nanoid": "3.3.8",
|
|
@@ -87,9 +88,9 @@
|
|
|
87
88
|
"access": "public"
|
|
88
89
|
},
|
|
89
90
|
"scripts": {
|
|
90
|
-
"sync": ". \"$HOME/.nvm/nvm.sh\" && nvm use && npm prune && npm install",
|
|
91
|
+
"sync": ". \"$HOME/.nvm/nvm.sh\" && nvm use && npm prune && npm install && npx drawbridge-agents-sync",
|
|
91
92
|
"build": "tsup && npm publish"
|
|
92
93
|
},
|
|
93
94
|
"types": "dist/index.d.ts",
|
|
94
|
-
"version": "0.0.
|
|
95
|
+
"version": "0.0.27"
|
|
95
96
|
}
|