@openpeepshq/common 0.1.43

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 (78) hide show
  1. package/LICENSE.md +21 -0
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +3 -0
  4. package/dist/lib/adminSections.d.ts +53 -0
  5. package/dist/lib/adminSections.js +62 -0
  6. package/dist/lib/attachmentHelpers.d.ts +1 -0
  7. package/dist/lib/attachmentHelpers.js +13 -0
  8. package/dist/lib/capabilitiesHelpers.d.ts +118 -0
  9. package/dist/lib/capabilitiesHelpers.js +238 -0
  10. package/dist/lib/colors.d.ts +5 -0
  11. package/dist/lib/colors.js +17 -0
  12. package/dist/lib/csvHelpers.d.ts +6 -0
  13. package/dist/lib/csvHelpers.js +17 -0
  14. package/dist/lib/eventIcs.d.ts +4 -0
  15. package/dist/lib/eventIcs.js +83 -0
  16. package/dist/lib/groupHelpers.d.ts +134 -0
  17. package/dist/lib/groupHelpers.js +216 -0
  18. package/dist/lib/index.d.ts +17 -0
  19. package/dist/lib/index.js +17 -0
  20. package/dist/lib/jamHelpers.d.ts +5 -0
  21. package/dist/lib/jamHelpers.js +37 -0
  22. package/dist/lib/markdownHelpers.d.ts +1 -0
  23. package/dist/lib/markdownHelpers.js +24 -0
  24. package/dist/lib/mediaDimensions.d.ts +19 -0
  25. package/dist/lib/mediaDimensions.js +19 -0
  26. package/dist/lib/postHelpers.d.ts +146 -0
  27. package/dist/lib/postHelpers.js +144 -0
  28. package/dist/lib/profileHelpers.d.ts +30 -0
  29. package/dist/lib/profileHelpers.js +75 -0
  30. package/dist/lib/pushHelpers.d.ts +4 -0
  31. package/dist/lib/pushHelpers.js +6 -0
  32. package/dist/lib/scopeHelpers.d.ts +25 -0
  33. package/dist/lib/scopeHelpers.js +85 -0
  34. package/dist/lib/text.d.ts +3 -0
  35. package/dist/lib/text.js +18 -0
  36. package/dist/lib/tokenHelpers.d.ts +21 -0
  37. package/dist/lib/tokenHelpers.js +81 -0
  38. package/dist/lib/utils.d.ts +43 -0
  39. package/dist/lib/utils.js +200 -0
  40. package/dist/types/admin-db.d.ts +62 -0
  41. package/dist/types/admin-db.js +41 -0
  42. package/dist/types/admin-email.d.ts +39 -0
  43. package/dist/types/admin-email.js +41 -0
  44. package/dist/types/admin-jobs.d.ts +15 -0
  45. package/dist/types/admin-jobs.js +14 -0
  46. package/dist/types/admin-performance.d.ts +23 -0
  47. package/dist/types/admin-performance.js +14 -0
  48. package/dist/types/analytics.d.ts +583 -0
  49. package/dist/types/analytics.js +213 -0
  50. package/dist/types/api.d.ts +20076 -0
  51. package/dist/types/api.js +492 -0
  52. package/dist/types/apple-app-site-association.d.ts +50 -0
  53. package/dist/types/apple-app-site-association.js +38 -0
  54. package/dist/types/auth.d.ts +367 -0
  55. package/dist/types/auth.js +17 -0
  56. package/dist/types/capabilities.d.ts +24 -0
  57. package/dist/types/capabilities.js +144 -0
  58. package/dist/types/config.d.ts +858 -0
  59. package/dist/types/config.js +352 -0
  60. package/dist/types/db.d.ts +8780 -0
  61. package/dist/types/db.js +65 -0
  62. package/dist/types/index.d.ts +18 -0
  63. package/dist/types/index.js +18 -0
  64. package/dist/types/internal.d.ts +44337 -0
  65. package/dist/types/internal.js +154 -0
  66. package/dist/types/models.d.ts +2619 -0
  67. package/dist/types/models.js +599 -0
  68. package/dist/types/notifications.d.ts +148 -0
  69. package/dist/types/notifications.js +40 -0
  70. package/dist/types/plugins.d.ts +66 -0
  71. package/dist/types/plugins.js +29 -0
  72. package/dist/types/stats.d.ts +10216 -0
  73. package/dist/types/stats.js +109 -0
  74. package/dist/types/stripe.d.ts +42 -0
  75. package/dist/types/stripe.js +35 -0
  76. package/dist/types/utils.d.ts +84 -0
  77. package/dist/types/utils.js +39 -0
  78. package/package.json +54 -0
@@ -0,0 +1,109 @@
1
+ import { z } from 'zod';
2
+ import { publicPostSchema, publicProfileSchema } from './api.js';
3
+ const objectStatsSchema = z.object({
4
+ day: z.object({
5
+ currentPeriod: z.number(),
6
+ lastPeriod: z.number(),
7
+ }),
8
+ week: z.object({
9
+ currentPeriod: z.number(),
10
+ lastPeriod: z.number(),
11
+ }),
12
+ month: z.object({
13
+ currentPeriod: z.number(),
14
+ lastPeriod: z.number(),
15
+ }),
16
+ quarter: z.object({
17
+ currentPeriod: z.number(),
18
+ lastPeriod: z.number(),
19
+ }),
20
+ year: z.object({
21
+ currentPeriod: z.number(),
22
+ lastPeriod: z.number(),
23
+ }),
24
+ });
25
+ const objectStatsWithAllSchema = objectStatsSchema.extend({
26
+ all: z.number(),
27
+ });
28
+ export const publicPostWithActivityScoreSchema = publicPostSchema.extend({
29
+ activityScore: z.number(),
30
+ });
31
+ export const publicProfileWithActivityScoreSchema = publicProfileSchema.extend({
32
+ activityScore: z.number(),
33
+ });
34
+ const topPostsListSchema = publicPostWithActivityScoreSchema.array().max(5);
35
+ const _topProfilesListSchema = publicProfileWithActivityScoreSchema
36
+ .array()
37
+ .max(5);
38
+ export const topPostsSchema = z.object({
39
+ day: topPostsListSchema,
40
+ week: topPostsListSchema,
41
+ month: topPostsListSchema,
42
+ quarter: topPostsListSchema,
43
+ year: topPostsListSchema,
44
+ });
45
+ export const topProfilesSchema = z.object({
46
+ day: publicProfileWithActivityScoreSchema.array().max(5),
47
+ week: publicProfileWithActivityScoreSchema.array().max(5),
48
+ month: publicProfileWithActivityScoreSchema.array().max(5),
49
+ quarter: publicProfileWithActivityScoreSchema.array().max(5),
50
+ year: publicProfileWithActivityScoreSchema.array().max(5),
51
+ });
52
+ export const profilesStatsSchema = z.object({
53
+ all: objectStatsWithAllSchema,
54
+ active: objectStatsWithAllSchema,
55
+ });
56
+ export const postsStatsSchema = z.object({
57
+ all: objectStatsWithAllSchema,
58
+ withoutReply: objectStatsWithAllSchema,
59
+ withReplies: objectStatsWithAllSchema,
60
+ replies: objectStatsWithAllSchema,
61
+ });
62
+ export const interactionsStatsSchema = z.object({
63
+ all: objectStatsWithAllSchema,
64
+ });
65
+ export const jamsStatsSchema = z.object({
66
+ sessions: objectStatsWithAllSchema,
67
+ participants: objectStatsWithAllSchema,
68
+ });
69
+ export const topListsStatsSchema = z.object({
70
+ posts: topPostsSchema,
71
+ profiles: topProfilesSchema,
72
+ });
73
+ export const timelinesStatsSchema = z.object({
74
+ signups: z.object({
75
+ week: z
76
+ .object({
77
+ name: z.string(),
78
+ count: z.number(),
79
+ })
80
+ .array(),
81
+ fourWeeks: z
82
+ .object({
83
+ name: z.string(),
84
+ count: z.number(),
85
+ })
86
+ .array(),
87
+ fourMonths: z
88
+ .object({
89
+ name: z.string(),
90
+ count: z.number(),
91
+ })
92
+ .array(),
93
+ }),
94
+ });
95
+ export const serverCountsSchema = z.object({
96
+ profiles: z.number(),
97
+ posts: z.number(),
98
+ events: z.number(),
99
+ reactions: z.number(),
100
+ rsvps: z.number(),
101
+ });
102
+ export const adminServerStatsSchema = z.object({
103
+ profiles: profilesStatsSchema,
104
+ posts: postsStatsSchema,
105
+ interactions: interactionsStatsSchema,
106
+ jams: jamsStatsSchema,
107
+ topLists: topListsStatsSchema,
108
+ timelines: timelinesStatsSchema,
109
+ });
@@ -0,0 +1,42 @@
1
+ import { z } from 'zod';
2
+ export declare const stripeSubscriptionStatusSchema: z.ZodEnum<{
3
+ active: "active";
4
+ incomplete: "incomplete";
5
+ incomplete_expired: "incomplete_expired";
6
+ trialing: "trialing";
7
+ past_due: "past_due";
8
+ canceled: "canceled";
9
+ unpaid: "unpaid";
10
+ paused: "paused";
11
+ }>;
12
+ export declare const stripeSubscriptionDataSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
13
+ subscriptionId: z.ZodNullable<z.ZodString>;
14
+ status: z.ZodEnum<{
15
+ active: "active";
16
+ incomplete: "incomplete";
17
+ incomplete_expired: "incomplete_expired";
18
+ trialing: "trialing";
19
+ past_due: "past_due";
20
+ canceled: "canceled";
21
+ unpaid: "unpaid";
22
+ paused: "paused";
23
+ }>;
24
+ priceId: z.ZodNullable<z.ZodString>;
25
+ currentPeriodStart: z.ZodNullable<z.ZodNumber>;
26
+ currentPeriodEnd: z.ZodNullable<z.ZodNumber>;
27
+ cancelAtPeriodEnd: z.ZodBoolean;
28
+ paymentMethod: z.ZodNullable<z.ZodObject<{
29
+ brand: z.ZodNullable<z.ZodString>;
30
+ last4: z.ZodNullable<z.ZodString>;
31
+ }, z.core.$strip>>;
32
+ }, z.core.$strip>, z.ZodObject<{
33
+ status: z.ZodLiteral<"none">;
34
+ }, z.core.$strip>], "status">;
35
+ export declare const stripeCustomerPortalResponseSchema: z.ZodObject<{
36
+ success: z.ZodBoolean;
37
+ message: z.ZodOptional<z.ZodString>;
38
+ key: z.ZodOptional<z.ZodString>;
39
+ url: z.ZodOptional<z.ZodString>;
40
+ }, z.core.$strip>;
41
+ export type StripeSubscriptionData = z.infer<typeof stripeSubscriptionDataSchema>;
42
+ export type StripeCustomerPortalResponseSchema = z.infer<typeof stripeCustomerPortalResponseSchema>;
@@ -0,0 +1,35 @@
1
+ import { z } from 'zod';
2
+ import { successFailureResponseSchema } from './api.js';
3
+ export const stripeSubscriptionStatusSchema = z.enum([
4
+ 'incomplete',
5
+ 'incomplete_expired',
6
+ 'trialing',
7
+ 'active',
8
+ 'past_due',
9
+ 'canceled',
10
+ 'unpaid',
11
+ 'paused',
12
+ ]);
13
+ const paymentMethodSchema = z
14
+ .object({
15
+ brand: z.string().nullable(),
16
+ last4: z.string().nullable(),
17
+ })
18
+ .nullable();
19
+ export const stripeSubscriptionDataSchema = z.discriminatedUnion('status', [
20
+ z.object({
21
+ subscriptionId: z.string().nullable(),
22
+ status: stripeSubscriptionStatusSchema,
23
+ priceId: z.string().nullable(),
24
+ currentPeriodStart: z.number().nullable(),
25
+ currentPeriodEnd: z.number().nullable(),
26
+ cancelAtPeriodEnd: z.boolean(),
27
+ paymentMethod: paymentMethodSchema,
28
+ }),
29
+ z.object({
30
+ status: z.literal('none'),
31
+ }),
32
+ ]);
33
+ export const stripeCustomerPortalResponseSchema = successFailureResponseSchema.extend({
34
+ url: z.string().optional(),
35
+ });
@@ -0,0 +1,84 @@
1
+ import { z } from 'zod';
2
+ import { CommunityConfig } from './config';
3
+ import type { i18n, ResourceKey } from 'i18next';
4
+ type Literal = string | number | boolean | null | undefined;
5
+ export type Json = Literal | {
6
+ [key: string]: Json;
7
+ } | Json[];
8
+ export declare const jsonSchema: z.ZodType<Json>;
9
+ export declare const i18nResourceKeySchema: z.ZodType<ResourceKey>;
10
+ export declare const i18nResourceLanguageSchema: z.ZodRecord<z.ZodString, z.ZodType<ResourceKey, unknown, z.core.$ZodTypeInternals<ResourceKey, unknown>>>;
11
+ export declare const i18nResourceSchema: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodType<ResourceKey, unknown, z.core.$ZodTypeInternals<ResourceKey, unknown>>>>;
12
+ export declare const emailAttachmentSchema: z.ZodObject<{
13
+ filename: z.ZodString;
14
+ content: z.ZodString;
15
+ contentType: z.ZodOptional<z.ZodString>;
16
+ encoding: z.ZodOptional<z.ZodEnum<{
17
+ utf8: "utf8";
18
+ base64: "base64";
19
+ }>>;
20
+ }, z.core.$strip>;
21
+ export type EmailAttachment = z.infer<typeof emailAttachmentSchema>;
22
+ export declare const emailOptionsSchema: z.ZodObject<{
23
+ to: z.ZodString;
24
+ template: z.ZodString;
25
+ locals: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodType<Json, unknown, z.core.$ZodTypeInternals<Json, unknown>>>>;
26
+ attachments: z.ZodOptional<z.ZodArray<z.ZodObject<{
27
+ filename: z.ZodString;
28
+ content: z.ZodString;
29
+ contentType: z.ZodOptional<z.ZodString>;
30
+ encoding: z.ZodOptional<z.ZodEnum<{
31
+ utf8: "utf8";
32
+ base64: "base64";
33
+ }>>;
34
+ }, z.core.$strip>>>;
35
+ }, z.core.$strip>;
36
+ export type EmailOptions = z.infer<typeof emailOptionsSchema>;
37
+ export declare const renderedEmailSchema: z.ZodObject<{
38
+ to: z.ZodString;
39
+ template: z.ZodString;
40
+ subject: z.ZodString;
41
+ html: z.ZodString;
42
+ text: z.ZodString;
43
+ }, z.core.$strip>;
44
+ export type RenderedEmail = z.infer<typeof renderedEmailSchema>;
45
+ export interface EmailService {
46
+ send: (renderedEmail: EmailOptions) => Promise<void>;
47
+ render: (emailOptions: EmailOptions) => Promise<RenderedEmail>;
48
+ }
49
+ export interface EmailGlobals {
50
+ communityConfig: CommunityConfig;
51
+ serverData: {
52
+ rootUrl: string;
53
+ iosUrl?: string;
54
+ androidUrl?: string;
55
+ };
56
+ i18nContext: {
57
+ i18n: i18n;
58
+ t: i18n['t'];
59
+ };
60
+ }
61
+ export interface EmailOptionsWithGlobals extends EmailOptions {
62
+ globals: EmailGlobals;
63
+ }
64
+ export interface EmailRenderer {
65
+ (emailOptions: EmailOptionsWithGlobals & {
66
+ locals: Record<string, unknown>;
67
+ }): Promise<{
68
+ subject: string;
69
+ html: string;
70
+ }>;
71
+ }
72
+ export type Level = 'info' | 'warn' | 'error' | 'fatal' | 'debug' | 'trace';
73
+ export interface Logger {
74
+ info: (...args: unknown[]) => void;
75
+ warn: (...args: unknown[]) => void;
76
+ error: (...args: unknown[]) => void;
77
+ fatal: (...args: unknown[]) => void;
78
+ debug: (...args: unknown[]) => void;
79
+ trace: (...args: unknown[]) => void;
80
+ }
81
+ export interface LoggerFactory {
82
+ (ns: string, meta?: Record<string, unknown>): Logger;
83
+ }
84
+ export {};
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ // NOTE: we used to model Json/ResourceKey as `z.lazy(() => z.union([...]))` for
3
+ // proper recursive validation. zod 4 + @asteasolutions/zod-to-openapi v8 blow
4
+ // the stack when walking such circular schemas during OpenAPI generation
5
+ // (isNullableSchema → safeParse(null) → ZodError → JSON.stringify on the
6
+ // lazy ref). Since runtime validation of arbitrary JSON is permissive anyway,
7
+ // model them as `z.any()` with a stable OpenAPI id and cast the public type.
8
+ export const jsonSchema = z
9
+ .any()
10
+ .openapi('JsonValue', { type: 'object' });
11
+ export const i18nResourceKeySchema = z
12
+ .any()
13
+ .openapi('I18nResourceKey', {
14
+ type: 'object',
15
+ });
16
+ export const i18nResourceLanguageSchema = z.record(z.string(), i18nResourceKeySchema);
17
+ export const i18nResourceSchema = z.record(z.string(), i18nResourceLanguageSchema);
18
+ export const emailAttachmentSchema = z.object({
19
+ filename: z.string(),
20
+ /** Raw string content (e.g. an .ics body). Kept as a string so the options
21
+ * stay JSON-serializable across the email queue and HTTP render boundary. */
22
+ content: z.string(),
23
+ contentType: z.string().optional(),
24
+ /** Set to base64 when `content` is a base64-encoded binary payload (e.g. PDF). */
25
+ encoding: z.enum(['utf8', 'base64']).optional(),
26
+ });
27
+ export const emailOptionsSchema = z.object({
28
+ to: z.string(),
29
+ template: z.string(),
30
+ locals: z.record(z.string(), jsonSchema).optional(),
31
+ attachments: z.array(emailAttachmentSchema).optional(),
32
+ });
33
+ export const renderedEmailSchema = z.object({
34
+ to: z.string(),
35
+ template: z.string(),
36
+ subject: z.string(),
37
+ html: z.string(),
38
+ text: z.string(),
39
+ });
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@openpeepshq/common",
3
+ "version": "0.1.43",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "dependencies": {
7
+ "@asteasolutions/zod-to-openapi": "^8.5.0",
8
+ "date-fns": "^4.1.0",
9
+ "ical-generator": "^10.2.0",
10
+ "iso-639-1": "^3.1.5",
11
+ "jose": "^6.2.2",
12
+ "type-fest": "^5.5.0",
13
+ "validator": "^13.15.35",
14
+ "zod": "^4.4.3"
15
+ },
16
+ "main": "dist/index.js",
17
+ "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": "./dist/index.js",
20
+ "./*": "./dist/*/index.js"
21
+ },
22
+ "files": [
23
+ "/dist"
24
+ ],
25
+ "devDependencies": {
26
+ "@types/node": "^24.1.12",
27
+ "@types/validator": "^13.15.10",
28
+ "@typescript-eslint/eslint-plugin": "^8.19.0",
29
+ "@typescript-eslint/parser": "^8.19.0",
30
+ "@vitest/coverage-v8": "^2.1.8",
31
+ "@vitest/ui": "^2.1.8",
32
+ "concurrently": "^9.2.1",
33
+ "eslint": "^10.1.0",
34
+ "eslint-config-prettier": "^10.1.8",
35
+ "i18next": "^26.0.3",
36
+ "livekit-client": "^2.19.2",
37
+ "prettier": "^3.8.1",
38
+ "tsc-alias": "^1.8.16",
39
+ "typed-emitter": "^2.1.0",
40
+ "typescript": "^6.0.2",
41
+ "vitest": "^2.1.8"
42
+ },
43
+ "scripts": {
44
+ "lint": "prettier --check . && eslint .",
45
+ "format": "prettier --write .",
46
+ "clean": "rm -rf tsconfig.tsbuildinfo dist",
47
+ "build": "tsc && tsc-alias",
48
+ "build:watch": "tsc && tsc-alias && (concurrently \"tsc -w\" \"tsc-alias -w\")",
49
+ "test": "vitest",
50
+ "test:ui": "vitest --ui",
51
+ "test:run": "vitest run",
52
+ "test:coverage": "vitest run --coverage"
53
+ }
54
+ }