@nocobase/plugin-auth 0.17.0-alpha.7 → 0.18.0-alpha.2

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.
Files changed (63) hide show
  1. package/dist/client/authenticator.d.ts +13 -0
  2. package/dist/client/basic/SignInForm.d.ts +9 -0
  3. package/dist/client/basic/SignUpForm.d.ts +13 -0
  4. package/dist/client/basic/index.d.ts +3 -0
  5. package/dist/client/index.d.ts +21 -0
  6. package/dist/client/index.js +12 -2
  7. package/dist/client/pages/AuthLayout.d.ts +2 -0
  8. package/dist/client/pages/SignInPage.d.ts +16 -0
  9. package/dist/client/pages/SignUpPage.d.ts +21 -0
  10. package/dist/client/pages/index.d.ts +3 -0
  11. package/dist/client/settings/Options.d.ts +3 -2
  12. package/dist/externalVersion.js +14 -12
  13. package/dist/locale/en-US.json +4 -1
  14. package/dist/locale/zh-CN.json +4 -1
  15. package/dist/node_modules/cron/LICENSE +0 -0
  16. package/dist/node_modules/cron/lib/cron.js +1 -1
  17. package/dist/node_modules/cron/lib/job.js +0 -0
  18. package/dist/node_modules/cron/lib/time.js +33 -20
  19. package/dist/node_modules/cron/node_modules/luxon/build/amd/luxon.js +7826 -0
  20. package/dist/node_modules/cron/node_modules/luxon/build/cjs-browser/luxon.js +7824 -0
  21. package/dist/node_modules/cron/node_modules/luxon/build/es6/luxon.js +7217 -0
  22. package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.js +7829 -0
  23. package/dist/node_modules/cron/node_modules/luxon/build/global/luxon.min.js +1 -0
  24. package/dist/node_modules/cron/node_modules/luxon/build/node/luxon.js +6932 -0
  25. package/dist/node_modules/cron/node_modules/luxon/package.json +85 -0
  26. package/dist/node_modules/cron/node_modules/luxon/src/datetime.js +2248 -0
  27. package/dist/node_modules/cron/node_modules/luxon/src/duration.js +948 -0
  28. package/dist/node_modules/cron/node_modules/luxon/src/errors.js +61 -0
  29. package/dist/node_modules/cron/node_modules/luxon/src/impl/conversions.js +161 -0
  30. package/dist/node_modules/cron/node_modules/luxon/src/impl/diff.js +75 -0
  31. package/dist/node_modules/cron/node_modules/luxon/src/impl/digits.js +75 -0
  32. package/dist/node_modules/cron/node_modules/luxon/src/impl/english.js +233 -0
  33. package/dist/node_modules/cron/node_modules/luxon/src/impl/formats.js +176 -0
  34. package/dist/node_modules/cron/node_modules/luxon/src/impl/formatter.js +400 -0
  35. package/dist/node_modules/cron/node_modules/luxon/src/impl/invalid.js +14 -0
  36. package/dist/node_modules/cron/node_modules/luxon/src/impl/locale.js +494 -0
  37. package/dist/node_modules/cron/node_modules/luxon/src/impl/regexParser.js +335 -0
  38. package/dist/node_modules/cron/node_modules/luxon/src/impl/tokenParser.js +444 -0
  39. package/dist/node_modules/cron/node_modules/luxon/src/impl/util.js +274 -0
  40. package/dist/node_modules/cron/node_modules/luxon/src/impl/zoneUtil.js +34 -0
  41. package/dist/node_modules/cron/node_modules/luxon/src/info.js +169 -0
  42. package/dist/node_modules/cron/node_modules/luxon/src/interval.js +637 -0
  43. package/dist/node_modules/cron/node_modules/luxon/src/luxon.js +26 -0
  44. package/dist/node_modules/cron/node_modules/luxon/src/package.json +4 -0
  45. package/dist/node_modules/cron/node_modules/luxon/src/settings.js +148 -0
  46. package/dist/node_modules/cron/node_modules/luxon/src/zone.js +91 -0
  47. package/dist/node_modules/cron/node_modules/luxon/src/zones/IANAZone.js +189 -0
  48. package/dist/node_modules/cron/node_modules/luxon/src/zones/fixedOffsetZone.js +102 -0
  49. package/dist/node_modules/cron/node_modules/luxon/src/zones/invalidZone.js +53 -0
  50. package/dist/node_modules/cron/node_modules/luxon/src/zones/systemZone.js +61 -0
  51. package/dist/node_modules/cron/package.json +1 -1
  52. package/dist/node_modules/cron/types/index.d.ts +181 -0
  53. package/dist/node_modules/cron/types/index.test-d.ts +85 -0
  54. package/dist/server/actions/authenticators.js +3 -0
  55. package/dist/server/basic-auth.js +5 -2
  56. package/dist/server/migrations/20231218132032-fix-allow-signup.d.ts +5 -0
  57. package/dist/server/migrations/20231218132032-fix-allow-signup.js +54 -0
  58. package/dist/server/model/authenticator.d.ts +5 -2
  59. package/dist/server/model/authenticator.js +2 -2
  60. package/package.json +2 -2
  61. package/dist/client/AuthPluginProvider.d.ts +0 -2
  62. package/dist/client/basic/SigninPage.d.ts +0 -6
  63. package/dist/client/basic/SignupPage.d.ts +0 -5
@@ -0,0 +1,494 @@
1
+ import { padStart, roundTo, hasRelative, formatOffset } from "./util.js";
2
+ import * as English from "./english.js";
3
+ import Settings from "../settings.js";
4
+ import DateTime from "../datetime.js";
5
+ import IANAZone from "../zones/IANAZone.js";
6
+
7
+ // todo - remap caching
8
+
9
+ let intlLFCache = {};
10
+ function getCachedLF(locString, opts = {}) {
11
+ const key = JSON.stringify([locString, opts]);
12
+ let dtf = intlLFCache[key];
13
+ if (!dtf) {
14
+ dtf = new Intl.ListFormat(locString, opts);
15
+ intlLFCache[key] = dtf;
16
+ }
17
+ return dtf;
18
+ }
19
+
20
+ let intlDTCache = {};
21
+ function getCachedDTF(locString, opts = {}) {
22
+ const key = JSON.stringify([locString, opts]);
23
+ let dtf = intlDTCache[key];
24
+ if (!dtf) {
25
+ dtf = new Intl.DateTimeFormat(locString, opts);
26
+ intlDTCache[key] = dtf;
27
+ }
28
+ return dtf;
29
+ }
30
+
31
+ let intlNumCache = {};
32
+ function getCachedINF(locString, opts = {}) {
33
+ const key = JSON.stringify([locString, opts]);
34
+ let inf = intlNumCache[key];
35
+ if (!inf) {
36
+ inf = new Intl.NumberFormat(locString, opts);
37
+ intlNumCache[key] = inf;
38
+ }
39
+ return inf;
40
+ }
41
+
42
+ let intlRelCache = {};
43
+ function getCachedRTF(locString, opts = {}) {
44
+ const { base, ...cacheKeyOpts } = opts; // exclude `base` from the options
45
+ const key = JSON.stringify([locString, cacheKeyOpts]);
46
+ let inf = intlRelCache[key];
47
+ if (!inf) {
48
+ inf = new Intl.RelativeTimeFormat(locString, opts);
49
+ intlRelCache[key] = inf;
50
+ }
51
+ return inf;
52
+ }
53
+
54
+ let sysLocaleCache = null;
55
+ function systemLocale() {
56
+ if (sysLocaleCache) {
57
+ return sysLocaleCache;
58
+ } else {
59
+ sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale;
60
+ return sysLocaleCache;
61
+ }
62
+ }
63
+
64
+ function parseLocaleString(localeStr) {
65
+ // I really want to avoid writing a BCP 47 parser
66
+ // see, e.g. https://github.com/wooorm/bcp-47
67
+ // Instead, we'll do this:
68
+
69
+ // a) if the string has no -u extensions, just leave it alone
70
+ // b) if it does, use Intl to resolve everything
71
+ // c) if Intl fails, try again without the -u
72
+
73
+ // private subtags and unicode subtags have ordering requirements,
74
+ // and we're not properly parsing this, so just strip out the
75
+ // private ones if they exist.
76
+ const xIndex = localeStr.indexOf("-x-");
77
+ if (xIndex !== -1) {
78
+ localeStr = localeStr.substring(0, xIndex);
79
+ }
80
+
81
+ const uIndex = localeStr.indexOf("-u-");
82
+ if (uIndex === -1) {
83
+ return [localeStr];
84
+ } else {
85
+ let options;
86
+ let selectedStr;
87
+ try {
88
+ options = getCachedDTF(localeStr).resolvedOptions();
89
+ selectedStr = localeStr;
90
+ } catch (e) {
91
+ const smaller = localeStr.substring(0, uIndex);
92
+ options = getCachedDTF(smaller).resolvedOptions();
93
+ selectedStr = smaller;
94
+ }
95
+
96
+ const { numberingSystem, calendar } = options;
97
+ return [selectedStr, numberingSystem, calendar];
98
+ }
99
+ }
100
+
101
+ function intlConfigString(localeStr, numberingSystem, outputCalendar) {
102
+ if (outputCalendar || numberingSystem) {
103
+ if (!localeStr.includes("-u-")) {
104
+ localeStr += "-u";
105
+ }
106
+
107
+ if (outputCalendar) {
108
+ localeStr += `-ca-${outputCalendar}`;
109
+ }
110
+
111
+ if (numberingSystem) {
112
+ localeStr += `-nu-${numberingSystem}`;
113
+ }
114
+ return localeStr;
115
+ } else {
116
+ return localeStr;
117
+ }
118
+ }
119
+
120
+ function mapMonths(f) {
121
+ const ms = [];
122
+ for (let i = 1; i <= 12; i++) {
123
+ const dt = DateTime.utc(2016, i, 1);
124
+ ms.push(f(dt));
125
+ }
126
+ return ms;
127
+ }
128
+
129
+ function mapWeekdays(f) {
130
+ const ms = [];
131
+ for (let i = 1; i <= 7; i++) {
132
+ const dt = DateTime.utc(2016, 11, 13 + i);
133
+ ms.push(f(dt));
134
+ }
135
+ return ms;
136
+ }
137
+
138
+ function listStuff(loc, length, defaultOK, englishFn, intlFn) {
139
+ const mode = loc.listingMode(defaultOK);
140
+
141
+ if (mode === "error") {
142
+ return null;
143
+ } else if (mode === "en") {
144
+ return englishFn(length);
145
+ } else {
146
+ return intlFn(length);
147
+ }
148
+ }
149
+
150
+ function supportsFastNumbers(loc) {
151
+ if (loc.numberingSystem && loc.numberingSystem !== "latn") {
152
+ return false;
153
+ } else {
154
+ return (
155
+ loc.numberingSystem === "latn" ||
156
+ !loc.locale ||
157
+ loc.locale.startsWith("en") ||
158
+ new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn"
159
+ );
160
+ }
161
+ }
162
+
163
+ /**
164
+ * @private
165
+ */
166
+
167
+ class PolyNumberFormatter {
168
+ constructor(intl, forceSimple, opts) {
169
+ this.padTo = opts.padTo || 0;
170
+ this.floor = opts.floor || false;
171
+
172
+ const { padTo, floor, ...otherOpts } = opts;
173
+
174
+ if (!forceSimple || Object.keys(otherOpts).length > 0) {
175
+ const intlOpts = { useGrouping: false, ...opts };
176
+ if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo;
177
+ this.inf = getCachedINF(intl, intlOpts);
178
+ }
179
+ }
180
+
181
+ format(i) {
182
+ if (this.inf) {
183
+ const fixed = this.floor ? Math.floor(i) : i;
184
+ return this.inf.format(fixed);
185
+ } else {
186
+ // to match the browser's numberformatter defaults
187
+ const fixed = this.floor ? Math.floor(i) : roundTo(i, 3);
188
+ return padStart(fixed, this.padTo);
189
+ }
190
+ }
191
+ }
192
+
193
+ /**
194
+ * @private
195
+ */
196
+
197
+ class PolyDateFormatter {
198
+ constructor(dt, intl, opts) {
199
+ this.opts = opts;
200
+ this.originalZone = undefined;
201
+
202
+ let z = undefined;
203
+ if (this.opts.timeZone) {
204
+ // Don't apply any workarounds if a timeZone is explicitly provided in opts
205
+ this.dt = dt;
206
+ } else if (dt.zone.type === "fixed") {
207
+ // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
208
+ // That is why fixed-offset TZ is set to that unless it is:
209
+ // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
210
+ // 2. Unsupported by the browser:
211
+ // - some do not support Etc/
212
+ // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
213
+ const gmtOffset = -1 * (dt.offset / 60);
214
+ const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`;
215
+ if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) {
216
+ z = offsetZ;
217
+ this.dt = dt;
218
+ } else {
219
+ // Not all fixed-offset zones like Etc/+4:30 are present in tzdata so
220
+ // we manually apply the offset and substitute the zone as needed.
221
+ z = "UTC";
222
+ this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset });
223
+ this.originalZone = dt.zone;
224
+ }
225
+ } else if (dt.zone.type === "system") {
226
+ this.dt = dt;
227
+ } else if (dt.zone.type === "iana") {
228
+ this.dt = dt;
229
+ z = dt.zone.name;
230
+ } else {
231
+ // Custom zones can have any offset / offsetName so we just manually
232
+ // apply the offset and substitute the zone as needed.
233
+ z = "UTC";
234
+ this.dt = dt.setZone("UTC").plus({ minutes: dt.offset });
235
+ this.originalZone = dt.zone;
236
+ }
237
+
238
+ const intlOpts = { ...this.opts };
239
+ intlOpts.timeZone = intlOpts.timeZone || z;
240
+ this.dtf = getCachedDTF(intl, intlOpts);
241
+ }
242
+
243
+ format() {
244
+ if (this.originalZone) {
245
+ // If we have to substitute in the actual zone name, we have to use
246
+ // formatToParts so that the timezone can be replaced.
247
+ return this.formatToParts()
248
+ .map(({ value }) => value)
249
+ .join("");
250
+ }
251
+ return this.dtf.format(this.dt.toJSDate());
252
+ }
253
+
254
+ formatToParts() {
255
+ const parts = this.dtf.formatToParts(this.dt.toJSDate());
256
+ if (this.originalZone) {
257
+ return parts.map((part) => {
258
+ if (part.type === "timeZoneName") {
259
+ const offsetName = this.originalZone.offsetName(this.dt.ts, {
260
+ locale: this.dt.locale,
261
+ format: this.opts.timeZoneName,
262
+ });
263
+ return {
264
+ ...part,
265
+ value: offsetName,
266
+ };
267
+ } else {
268
+ return part;
269
+ }
270
+ });
271
+ }
272
+ return parts;
273
+ }
274
+
275
+ resolvedOptions() {
276
+ return this.dtf.resolvedOptions();
277
+ }
278
+ }
279
+
280
+ /**
281
+ * @private
282
+ */
283
+ class PolyRelFormatter {
284
+ constructor(intl, isEnglish, opts) {
285
+ this.opts = { style: "long", ...opts };
286
+ if (!isEnglish && hasRelative()) {
287
+ this.rtf = getCachedRTF(intl, opts);
288
+ }
289
+ }
290
+
291
+ format(count, unit) {
292
+ if (this.rtf) {
293
+ return this.rtf.format(count, unit);
294
+ } else {
295
+ return English.formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long");
296
+ }
297
+ }
298
+
299
+ formatToParts(count, unit) {
300
+ if (this.rtf) {
301
+ return this.rtf.formatToParts(count, unit);
302
+ } else {
303
+ return [];
304
+ }
305
+ }
306
+ }
307
+
308
+ /**
309
+ * @private
310
+ */
311
+
312
+ export default class Locale {
313
+ static fromOpts(opts) {
314
+ return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN);
315
+ }
316
+
317
+ static create(locale, numberingSystem, outputCalendar, defaultToEN = false) {
318
+ const specifiedLocale = locale || Settings.defaultLocale;
319
+ // the system locale is useful for human readable strings but annoying for parsing/formatting known formats
320
+ const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale());
321
+ const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem;
322
+ const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar;
323
+ return new Locale(localeR, numberingSystemR, outputCalendarR, specifiedLocale);
324
+ }
325
+
326
+ static resetCache() {
327
+ sysLocaleCache = null;
328
+ intlDTCache = {};
329
+ intlNumCache = {};
330
+ intlRelCache = {};
331
+ }
332
+
333
+ static fromObject({ locale, numberingSystem, outputCalendar } = {}) {
334
+ return Locale.create(locale, numberingSystem, outputCalendar);
335
+ }
336
+
337
+ constructor(locale, numbering, outputCalendar, specifiedLocale) {
338
+ const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale);
339
+
340
+ this.locale = parsedLocale;
341
+ this.numberingSystem = numbering || parsedNumberingSystem || null;
342
+ this.outputCalendar = outputCalendar || parsedOutputCalendar || null;
343
+ this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar);
344
+
345
+ this.weekdaysCache = { format: {}, standalone: {} };
346
+ this.monthsCache = { format: {}, standalone: {} };
347
+ this.meridiemCache = null;
348
+ this.eraCache = {};
349
+
350
+ this.specifiedLocale = specifiedLocale;
351
+ this.fastNumbersCached = null;
352
+ }
353
+
354
+ get fastNumbers() {
355
+ if (this.fastNumbersCached == null) {
356
+ this.fastNumbersCached = supportsFastNumbers(this);
357
+ }
358
+
359
+ return this.fastNumbersCached;
360
+ }
361
+
362
+ listingMode() {
363
+ const isActuallyEn = this.isEnglish();
364
+ const hasNoWeirdness =
365
+ (this.numberingSystem === null || this.numberingSystem === "latn") &&
366
+ (this.outputCalendar === null || this.outputCalendar === "gregory");
367
+ return isActuallyEn && hasNoWeirdness ? "en" : "intl";
368
+ }
369
+
370
+ clone(alts) {
371
+ if (!alts || Object.getOwnPropertyNames(alts).length === 0) {
372
+ return this;
373
+ } else {
374
+ return Locale.create(
375
+ alts.locale || this.specifiedLocale,
376
+ alts.numberingSystem || this.numberingSystem,
377
+ alts.outputCalendar || this.outputCalendar,
378
+ alts.defaultToEN || false
379
+ );
380
+ }
381
+ }
382
+
383
+ redefaultToEN(alts = {}) {
384
+ return this.clone({ ...alts, defaultToEN: true });
385
+ }
386
+
387
+ redefaultToSystem(alts = {}) {
388
+ return this.clone({ ...alts, defaultToEN: false });
389
+ }
390
+
391
+ months(length, format = false, defaultOK = true) {
392
+ return listStuff(this, length, defaultOK, English.months, () => {
393
+ const intl = format ? { month: length, day: "numeric" } : { month: length },
394
+ formatStr = format ? "format" : "standalone";
395
+ if (!this.monthsCache[formatStr][length]) {
396
+ this.monthsCache[formatStr][length] = mapMonths((dt) => this.extract(dt, intl, "month"));
397
+ }
398
+ return this.monthsCache[formatStr][length];
399
+ });
400
+ }
401
+
402
+ weekdays(length, format = false, defaultOK = true) {
403
+ return listStuff(this, length, defaultOK, English.weekdays, () => {
404
+ const intl = format
405
+ ? { weekday: length, year: "numeric", month: "long", day: "numeric" }
406
+ : { weekday: length },
407
+ formatStr = format ? "format" : "standalone";
408
+ if (!this.weekdaysCache[formatStr][length]) {
409
+ this.weekdaysCache[formatStr][length] = mapWeekdays((dt) =>
410
+ this.extract(dt, intl, "weekday")
411
+ );
412
+ }
413
+ return this.weekdaysCache[formatStr][length];
414
+ });
415
+ }
416
+
417
+ meridiems(defaultOK = true) {
418
+ return listStuff(
419
+ this,
420
+ undefined,
421
+ defaultOK,
422
+ () => English.meridiems,
423
+ () => {
424
+ // In theory there could be aribitrary day periods. We're gonna assume there are exactly two
425
+ // for AM and PM. This is probably wrong, but it's makes parsing way easier.
426
+ if (!this.meridiemCache) {
427
+ const intl = { hour: "numeric", hourCycle: "h12" };
428
+ this.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map(
429
+ (dt) => this.extract(dt, intl, "dayperiod")
430
+ );
431
+ }
432
+
433
+ return this.meridiemCache;
434
+ }
435
+ );
436
+ }
437
+
438
+ eras(length, defaultOK = true) {
439
+ return listStuff(this, length, defaultOK, English.eras, () => {
440
+ const intl = { era: length };
441
+
442
+ // This is problematic. Different calendars are going to define eras totally differently. What I need is the minimum set of dates
443
+ // to definitely enumerate them.
444
+ if (!this.eraCache[length]) {
445
+ this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map((dt) =>
446
+ this.extract(dt, intl, "era")
447
+ );
448
+ }
449
+
450
+ return this.eraCache[length];
451
+ });
452
+ }
453
+
454
+ extract(dt, intlOpts, field) {
455
+ const df = this.dtFormatter(dt, intlOpts),
456
+ results = df.formatToParts(),
457
+ matching = results.find((m) => m.type.toLowerCase() === field);
458
+ return matching ? matching.value : null;
459
+ }
460
+
461
+ numberFormatter(opts = {}) {
462
+ // this forcesimple option is never used (the only caller short-circuits on it, but it seems safer to leave)
463
+ // (in contrast, the rest of the condition is used heavily)
464
+ return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts);
465
+ }
466
+
467
+ dtFormatter(dt, intlOpts = {}) {
468
+ return new PolyDateFormatter(dt, this.intl, intlOpts);
469
+ }
470
+
471
+ relFormatter(opts = {}) {
472
+ return new PolyRelFormatter(this.intl, this.isEnglish(), opts);
473
+ }
474
+
475
+ listFormatter(opts = {}) {
476
+ return getCachedLF(this.intl, opts);
477
+ }
478
+
479
+ isEnglish() {
480
+ return (
481
+ this.locale === "en" ||
482
+ this.locale.toLowerCase() === "en-us" ||
483
+ new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us")
484
+ );
485
+ }
486
+
487
+ equals(other) {
488
+ return (
489
+ this.locale === other.locale &&
490
+ this.numberingSystem === other.numberingSystem &&
491
+ this.outputCalendar === other.outputCalendar
492
+ );
493
+ }
494
+ }