@drawbridge/drawbridge-utils 0.0.2 → 0.0.4

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.js CHANGED
@@ -1,15 +1,212 @@
1
1
  // index.js
2
+ import { code, data } from "currency-codes";
3
+
4
+ // lib/constants.js
5
+ var font = {
6
+ family: "Roboto Flex",
7
+ transform: "none",
8
+ weight: "regular"
9
+ };
10
+ var constants_default = {
11
+ action: {
12
+ usage: {
13
+ actions: 0
14
+ }
15
+ },
16
+ brand: {
17
+ style: {
18
+ body: font,
19
+ heading: font
20
+ },
21
+ totals: {
22
+ campaigns: 0
23
+ }
24
+ },
25
+ campaign: {
26
+ agreements: {
27
+ marketing: {
28
+ enabled: false,
29
+ label: "I agree to the marketing terms and conditions",
30
+ link: null
31
+ },
32
+ terms: {
33
+ enabled: false,
34
+ label: "I agree to the terms and conditions",
35
+ link: null
36
+ }
37
+ },
38
+ defaults: {
39
+ active: "Enter",
40
+ confirmation: "Submission was successful",
41
+ inactive: "Submissions are closed",
42
+ email: "You were selected"
43
+ },
44
+ notifications: {
45
+ draw: {
46
+ subject: "You have been selected",
47
+ body: "Thanks for being part of our giveaway"
48
+ }
49
+ },
50
+ settings: {
51
+ submissionLeadPrimaryKey: "email",
52
+ submissionEntryMaximum: 1,
53
+ submissionEntryFilter: "campaign",
54
+ submissionEntryHighscore: false,
55
+ submissionEntryLimit: 1
56
+ },
57
+ status: "drafted",
58
+ totals: {
59
+ advertisements: 0,
60
+ affiliates: 0,
61
+ draws: 0,
62
+ exports: 0,
63
+ entries: 0,
64
+ fields: 2,
65
+ integrations: 1,
66
+ leads: 0,
67
+ links: 0,
68
+ pages: 0,
69
+ prizes: 0,
70
+ ranges: 0,
71
+ submissions: 0
72
+ },
73
+ type: "giveaway"
74
+ },
75
+ draw: {
76
+ status: "qualified",
77
+ totals: {
78
+ notifications: 0
79
+ }
80
+ },
81
+ member: {
82
+ status: "pending"
83
+ },
84
+ organization: {
85
+ errors: [],
86
+ totals: {
87
+ affiliates: 0,
88
+ brands: 0,
89
+ campaigns: 0,
90
+ leads: 0,
91
+ draws: 0,
92
+ entries: 0,
93
+ invitations: 0,
94
+ invoices: 0,
95
+ members: 0,
96
+ ranges: 0,
97
+ pages: 0,
98
+ prizes: 0,
99
+ storage: 0,
100
+ submissions: 0,
101
+ subscriptions: 0,
102
+ usage: 0
103
+ }
104
+ },
105
+ page: {
106
+ domains: [],
107
+ status: "drafted",
108
+ totals: {
109
+ leads: 0,
110
+ entries: 0,
111
+ submissions: 0
112
+ }
113
+ },
114
+ prize: {
115
+ inventory: 0,
116
+ remaining: 0,
117
+ shipping: false,
118
+ status: "drafted",
119
+ totals: {
120
+ draws: 0
121
+ }
122
+ },
123
+ range: {
124
+ totals: {
125
+ leads: 0,
126
+ entries: 0,
127
+ submissions: 0
128
+ }
129
+ },
130
+ referrer: {
131
+ totals: {
132
+ originizations: 0,
133
+ subscriptions: 0,
134
+ users: 0
135
+ }
136
+ },
137
+ template: {
138
+ page: {
139
+ style: {
140
+ body: font,
141
+ heading: font
142
+ }
143
+ }
144
+ },
145
+ usage: {
146
+ totals: {
147
+ actions: 0,
148
+ affiliates: 0,
149
+ brands: 0,
150
+ campaigns: 0,
151
+ connections: 0,
152
+ entries: 0,
153
+ files: 0,
154
+ members: 0,
155
+ orders: 0,
156
+ pages: 0,
157
+ revenue: 0,
158
+ storage: 0,
159
+ submissions: 0,
160
+ workflows: 0
161
+ }
162
+ },
163
+ user: {
164
+ access: {
165
+ ai: false
166
+ },
167
+ image: null,
168
+ totals: {
169
+ inbox: 0,
170
+ invitations: 0,
171
+ messages: 0,
172
+ methods: 0,
173
+ organizations: 1,
174
+ teams: 0
175
+ }
176
+ }
177
+ };
178
+
179
+ // index.js
180
+ var constants = constants_default;
2
181
  var infinite = 1e300;
3
182
  var isInfinite = (value) => value === infinite;
4
183
  var megabyte = 1024 * 1024;
5
184
  var gigabyte = megabyte * 1024;
6
185
  var urlRoot = (string) => (string == null ? void 0 : string.includes("https")) ? "https://" : "http://";
186
+ var bytesToGB = (bytes) => {
187
+ const divide = 1024 * 1024 * 1024;
188
+ return bytes ? Number(bytes) / divide : 0;
189
+ };
190
+ var bytesToMB = (bytes) => {
191
+ const divide = 1024 * 1024;
192
+ return bytes ? Number(bytes) / divide : 0;
193
+ };
7
194
  var capitalize = (string) => {
8
195
  var _a;
9
196
  return ((_a = string == null ? void 0 : string.charAt(0)) == null ? void 0 : _a.toUpperCase()) + (string == null ? void 0 : string.slice(1));
10
197
  };
198
+ var expiredPaymentMethod = (card) => {
199
+ const currentDate = /* @__PURE__ */ new Date();
200
+ const year = currentDate.getFullYear();
201
+ const month = (/* @__PURE__ */ new Date()).getMonth();
202
+ const expired = [
203
+ (card == null ? void 0 : card.year) < year,
204
+ (card == null ? void 0 : card.year) === year && (card == null ? void 0 : card.month) <= month
205
+ ].filter(Boolean);
206
+ return Boolean(expired == null ? void 0 : expired.length);
207
+ };
11
208
  var formatCurrency = ({
12
- code = "USD",
209
+ code: code2 = "USD",
13
210
  digits = 2,
14
211
  display = "standard",
15
212
  locale,
@@ -18,7 +215,7 @@ var formatCurrency = ({
18
215
  var _a;
19
216
  const resolvedLocale = locale || (typeof navigator !== "undefined" ? navigator == null ? void 0 : navigator.language : null) || "en-US";
20
217
  const options = {
21
- currency: code,
218
+ currency: code2,
22
219
  minimumFractionDigits: digits,
23
220
  maximumFractionDigits: digits,
24
221
  style: "currency"
@@ -28,7 +225,7 @@ var formatCurrency = ({
28
225
  const parts = new Intl.NumberFormat(resolvedLocale, options).formatToParts(value);
29
226
  const symbol = ((_a = parts.find((p) => p.type === "currency")) == null ? void 0 : _a.value) || "";
30
227
  const number = parts.filter((p) => p.type !== "currency" && p.type !== "literal").map((p) => p.value).join("");
31
- return symbol + number + " " + code;
228
+ return symbol + number + " " + code2;
32
229
  }
33
230
  ;
34
231
  return new Intl.NumberFormat(resolvedLocale, options).format(value);
@@ -66,6 +263,31 @@ var getPlanFeature = (plan, key) => {
66
263
  message: granted ? feature : error
67
264
  };
68
265
  };
266
+ var percentage = (value1, value2, decimals = 1) => ((value1 || 0) / (value2 || 0) * 100 || 0).toFixed(decimals);
267
+ var reducers = {
268
+ fields: (data2 = [], callback = () => ({})) => data2.reduce(
269
+ (accumulator, field) => {
270
+ const type = field == null ? void 0 : field.type;
271
+ if (!accumulator[type]) return accumulator;
272
+ accumulator[type].items.push({
273
+ ...field,
274
+ ...callback(field)
275
+ });
276
+ accumulator[type].keys.push(field == null ? void 0 : field.slug);
277
+ return accumulator;
278
+ },
279
+ {
280
+ additional: {
281
+ items: [],
282
+ keys: []
283
+ },
284
+ lead: {
285
+ items: [],
286
+ keys: []
287
+ }
288
+ }
289
+ )
290
+ };
69
291
  var regex = {
70
292
  domain: /^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/,
71
293
  protocols: /^(https?:\/\/)?(www\.)?/,
@@ -76,8 +298,10 @@ var shareUrls = ({
76
298
  organization,
77
299
  page
78
300
  }) => {
79
- const preface = urlRoot(formUri);
80
- const base = formUri;
301
+ var _a;
302
+ const resolvedFormUri = formUri || (typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.APP_CLIENT_FORM_URI : void 0);
303
+ const preface = urlRoot(resolvedFormUri);
304
+ const base = resolvedFormUri;
81
305
  const qr = preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId) + "?qr=1";
82
306
  const short = preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId);
83
307
  const url = preface + (organization == null ? void 0 : organization.subdomain) + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.slug);
@@ -110,8 +334,20 @@ var shareUrls = ({
110
334
  urls
111
335
  };
112
336
  };
113
- module.exports = {
337
+ var currencies = data.map((item) => ({
338
+ ...item,
339
+ key: item.currency,
340
+ value: item.code
341
+ }));
342
+ var currency = (val) => code(val);
343
+ export {
344
+ bytesToGB,
345
+ bytesToMB,
114
346
  capitalize,
347
+ constants,
348
+ currencies,
349
+ currency,
350
+ expiredPaymentMethod,
115
351
  formatCurrency,
116
352
  formatDateString,
117
353
  formatNumber,
@@ -120,6 +356,8 @@ module.exports = {
120
356
  infinite,
121
357
  isInfinite,
122
358
  megabyte,
359
+ percentage,
360
+ reducers,
123
361
  regex,
124
362
  shareUrls,
125
363
  urlRoot
package/package.json CHANGED
@@ -1,28 +1,35 @@
1
1
  {
2
+ "type": "module",
2
3
  "dependencies": {
4
+ "currency-codes": "2.2.0",
3
5
  "tsup": "8.5.1",
4
6
  "typescript": "5.9.3"
5
7
  },
6
8
  "exports": {
7
9
  ".": {
8
10
  "types": "./dist/index.d.ts",
9
- "import": "./dist/index.mjs",
10
- "require": "./dist/index.js"
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./encrypt": {
15
+ "types": "./dist/encrypt.d.ts",
16
+ "import": "./dist/encrypt.js",
17
+ "require": "./dist/encrypt.cjs"
11
18
  }
12
19
  },
13
20
  "files": [
14
21
  "dist"
15
22
  ],
16
23
  "license": "ISC",
17
- "main": "dist/index.js",
18
- "module": "dist/index.mjs",
24
+ "main": "dist/index.cjs",
25
+ "module": "dist/index.js",
19
26
  "name": "@drawbridge/drawbridge-utils",
20
27
  "publishConfig": {
21
28
  "access": "public"
22
29
  },
23
30
  "scripts": {
24
- "build": "tsup ./index.js && npm publish"
31
+ "build": "tsup && npm publish"
25
32
  },
26
33
  "types": "dist/index.d.ts",
27
- "version": "0.0.2"
34
+ "version": "0.0.4"
28
35
  }
package/dist/index.d.mts DELETED
@@ -1,169 +0,0 @@
1
- const infinite = 1e300;
2
-
3
- const isInfinite = ( value ) => value === infinite;
4
-
5
- const megabyte = ( 1024 * 1024 );
6
- const gigabyte = ( megabyte * 1024 );
7
-
8
- const urlRoot = ( string ) => ( string?.includes( 'https' ) ? 'https://' : 'http://' );
9
-
10
- const capitalize = ( string ) => {
11
-
12
- return string?.charAt( 0 )?.toUpperCase() + string?.slice( 1 );
13
-
14
- };
15
-
16
- const formatCurrency = ({
17
- code = 'USD',
18
- digits = 2,
19
- display = 'standard',
20
- locale,
21
- value = 0
22
- }) => {
23
-
24
- const resolvedLocale = locale
25
- || ( typeof navigator !== 'undefined' ? navigator?.language : null )
26
- || 'en-US';
27
-
28
- const options = {
29
- currency : code,
30
- minimumFractionDigits : digits,
31
- maximumFractionDigits : digits,
32
- style : 'currency'
33
- };
34
-
35
- if( display === 'parts' ){
36
-
37
- options.currencyDisplay = 'narrowSymbol';
38
-
39
- const parts = new Intl.NumberFormat( resolvedLocale, options ).formatToParts( value );
40
-
41
- const symbol = parts.find( ( p ) => p.type === 'currency' )?.value || '';
42
- const number = parts
43
- .filter( ( p ) => p.type !== 'currency' && p.type !== 'literal' )
44
- .map( ( p ) => p.value )
45
- .join( '' );
46
-
47
- return symbol + number + ' ' + code;
48
-
49
- }
50
- return new Intl.NumberFormat( resolvedLocale, options ).format( value );
51
-
52
- };
53
-
54
- const formatDateString = ({
55
- date,
56
- locale,
57
- time = false,
58
- options = {
59
- day : 'numeric',
60
- month : 'long',
61
- weekday : 'long',
62
- year : 'numeric'
63
- }
64
- }) => {
65
-
66
- const resolved = time
67
- ? { ...options, hour : 'numeric', minute : '2-digit' }
68
- : options;
69
-
70
- return new Date( date ).toLocaleString(
71
- locale,
72
- resolved
73
- );
74
-
75
- };
76
-
77
- const formatNumber = (
78
- number,
79
- digits = 0
80
- ) => {
81
-
82
- return Number( number ).toLocaleString( 'en', {
83
- minimumFractionDigits : digits,
84
- maximumFractionDigits : digits
85
- });
86
-
87
- };
88
-
89
- const getPlanFeature = ( plan, key ) => {
90
-
91
- const error = ( plan?.features?.denied || {} )?.[ key ];
92
- const feature = ( plan?.features?.granted || {} )?.[ key ];
93
- const granted = Boolean( feature );
94
-
95
- return {
96
- granted,
97
- message : granted ? feature : error
98
- };
99
-
100
- };
101
-
102
- const regex = {
103
- domain : /^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/,
104
- protocols : /^(https?:\/\/)?(www\.)?/,
105
- url : /^(https:\/\/)/
106
- };
107
-
108
- const shareUrls = ({
109
- formUri,
110
- organization,
111
- page
112
- }) => {
113
-
114
- const preface = urlRoot( formUri );
115
- const base = formUri;
116
-
117
- const qr = preface + base?.replace( preface, '' ) + '/' + page?.shortId + '?qr=1';
118
- const short = preface + base?.replace( preface, '' ) + '/' + page?.shortId;
119
- const url = preface + organization?.subdomain + '.' + base?.replace( preface, '' ) + '/' + page?.slug;
120
-
121
- const clients = [
122
- base,
123
- qr,
124
- short,
125
- url
126
- ];
127
-
128
- const urls = {
129
- qr,
130
- short,
131
- url
132
- };
133
-
134
- if( organization?.subdomain && page?.shortId ){
135
-
136
- clients.push( preface + base?.replace( preface, '' ) + '/' + page?.shortId );
137
- clients.push( preface + base?.replace( preface, '' ) + '/' + page?.shortId + '?qr=1' );
138
- clients.push( preface + organization.subdomain + '.' + base?.replace( preface, '' ) );
139
- clients.push( preface + organization.subdomain + '.' + base?.replace( preface, '' ) + '/' + page?.shortId );
140
-
141
- }
142
- if( organization?.shortId && page?.slug && page?.shortId ){
143
-
144
- clients.push( preface + organization.shortId + '.' + base?.replace( preface, '' ) );
145
- clients.push( preface + organization.shortId + '.' + base?.replace( preface, '' ) + '/' + page?.slug );
146
- clients.push( preface + organization.shortId + '.' + base?.replace( preface, '' ) + '/' + page?.shortId );
147
-
148
- }
149
- return {
150
- clients,
151
- urls
152
- };
153
-
154
- };
155
-
156
- module.exports = {
157
- capitalize,
158
- formatCurrency,
159
- formatDateString,
160
- formatNumber,
161
- getPlanFeature,
162
- gigabyte,
163
- infinite,
164
- isInfinite,
165
- megabyte,
166
- regex,
167
- shareUrls,
168
- urlRoot
169
- };
package/dist/index.mjs DELETED
@@ -1,136 +0,0 @@
1
- var __getOwnPropNames = Object.getOwnPropertyNames;
2
- var __commonJS = (cb, mod) => function __require() {
3
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
- };
5
-
6
- // index.js
7
- var require_index = __commonJS({
8
- "index.js"(exports, module) {
9
- var infinite = 1e300;
10
- var isInfinite = (value) => value === infinite;
11
- var megabyte = 1024 * 1024;
12
- var gigabyte = megabyte * 1024;
13
- var urlRoot = (string) => (string == null ? void 0 : string.includes("https")) ? "https://" : "http://";
14
- var capitalize = (string) => {
15
- var _a;
16
- return ((_a = string == null ? void 0 : string.charAt(0)) == null ? void 0 : _a.toUpperCase()) + (string == null ? void 0 : string.slice(1));
17
- };
18
- var formatCurrency = ({
19
- code = "USD",
20
- digits = 2,
21
- display = "standard",
22
- locale,
23
- value = 0
24
- }) => {
25
- var _a;
26
- const resolvedLocale = locale || (typeof navigator !== "undefined" ? navigator == null ? void 0 : navigator.language : null) || "en-US";
27
- const options = {
28
- currency: code,
29
- minimumFractionDigits: digits,
30
- maximumFractionDigits: digits,
31
- style: "currency"
32
- };
33
- if (display === "parts") {
34
- options.currencyDisplay = "narrowSymbol";
35
- const parts = new Intl.NumberFormat(resolvedLocale, options).formatToParts(value);
36
- const symbol = ((_a = parts.find((p) => p.type === "currency")) == null ? void 0 : _a.value) || "";
37
- const number = parts.filter((p) => p.type !== "currency" && p.type !== "literal").map((p) => p.value).join("");
38
- return symbol + number + " " + code;
39
- }
40
- ;
41
- return new Intl.NumberFormat(resolvedLocale, options).format(value);
42
- };
43
- var formatDateString = ({
44
- date,
45
- locale,
46
- time = false,
47
- options = {
48
- day: "numeric",
49
- month: "long",
50
- weekday: "long",
51
- year: "numeric"
52
- }
53
- }) => {
54
- const resolved = time ? { ...options, hour: "numeric", minute: "2-digit" } : options;
55
- return new Date(date).toLocaleString(
56
- locale,
57
- resolved
58
- );
59
- };
60
- var formatNumber = (number, digits = 0) => {
61
- return Number(number).toLocaleString("en", {
62
- minimumFractionDigits: digits,
63
- maximumFractionDigits: digits
64
- });
65
- };
66
- var getPlanFeature = (plan, key) => {
67
- var _a, _b, _c, _d;
68
- const error = (_b = ((_a = plan == null ? void 0 : plan.features) == null ? void 0 : _a.denied) || {}) == null ? void 0 : _b[key];
69
- const feature = (_d = ((_c = plan == null ? void 0 : plan.features) == null ? void 0 : _c.granted) || {}) == null ? void 0 : _d[key];
70
- const granted = Boolean(feature);
71
- return {
72
- granted,
73
- message: granted ? feature : error
74
- };
75
- };
76
- var regex = {
77
- domain: /^([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/,
78
- protocols: /^(https?:\/\/)?(www\.)?/,
79
- url: /^(https:\/\/)/
80
- };
81
- var shareUrls = ({
82
- formUri,
83
- organization,
84
- page
85
- }) => {
86
- const preface = urlRoot(formUri);
87
- const base = formUri;
88
- const qr = preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId) + "?qr=1";
89
- const short = preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId);
90
- const url = preface + (organization == null ? void 0 : organization.subdomain) + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.slug);
91
- const clients = [
92
- base,
93
- qr,
94
- short,
95
- url
96
- ];
97
- const urls = {
98
- qr,
99
- short,
100
- url
101
- };
102
- if ((organization == null ? void 0 : organization.subdomain) && (page == null ? void 0 : page.shortId)) {
103
- clients.push(preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId));
104
- clients.push(preface + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId) + "?qr=1");
105
- clients.push(preface + organization.subdomain + "." + (base == null ? void 0 : base.replace(preface, "")));
106
- clients.push(preface + organization.subdomain + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId));
107
- }
108
- ;
109
- if ((organization == null ? void 0 : organization.shortId) && (page == null ? void 0 : page.slug) && (page == null ? void 0 : page.shortId)) {
110
- clients.push(preface + organization.shortId + "." + (base == null ? void 0 : base.replace(preface, "")));
111
- clients.push(preface + organization.shortId + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.slug));
112
- clients.push(preface + organization.shortId + "." + (base == null ? void 0 : base.replace(preface, "")) + "/" + (page == null ? void 0 : page.shortId));
113
- }
114
- ;
115
- return {
116
- clients,
117
- urls
118
- };
119
- };
120
- module.exports = {
121
- capitalize,
122
- formatCurrency,
123
- formatDateString,
124
- formatNumber,
125
- getPlanFeature,
126
- gigabyte,
127
- infinite,
128
- isInfinite,
129
- megabyte,
130
- regex,
131
- shareUrls,
132
- urlRoot
133
- };
134
- }
135
- });
136
- export default require_index();