@zodic/shared 0.0.1 → 0.0.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zodic/shared",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -0,0 +1,3 @@
1
+ export * from './scopes/cloudflare';
2
+ export * from './scopes/db';
3
+ export * from './scopes/generic';
@@ -0,0 +1,2 @@
1
+ export * from './scopes/db';
2
+ export * from './scopes/generic';
package/types/index.ts CHANGED
@@ -1,197 +1,2 @@
1
- import {
2
- Ai,
3
- D1Database,
4
- KVNamespace,
5
- R2Bucket,
6
- } from '@cloudflare/workers-types';
7
- import { Context, Env } from 'hono';
8
- export * from './db';
9
-
10
- export type CentralBindings = {
11
- TEST_IMAGES_BUCKET: R2Bucket;
12
- PHOTOS_BUCKET: R2Bucket;
13
- OPENAI_API_KEY: string;
14
- LEONARDO_API_KEY: string;
15
- DESCRIBER_API_KEY: string;
16
- DESCRIBER_APP_ID: string;
17
- AKOOL_API_KEY: string;
18
- KV_GENERATION_MANAGEMENT: KVNamespace;
19
- KV_USER_GENERATIONS: KVNamespace;
20
- KV_ARCHETYPES: KVNamespace;
21
- KV_LEONARDO_PROMPTS: KVNamespace;
22
- KV_TEST: KVNamespace;
23
- PROMPT_IMAGE_DESCRIBER: string;
24
- PROMPT_GENERATE_ARCHETYPE: string;
25
- PROMPT_GENERATE_LEONARDO: string;
26
- NEGATIVE_PROMPT_LEONARDO: string;
27
- PROMPT_GENERATE_USER_LUMINOUS_SELF: string;
28
- AI: Ai;
29
- DB: D1Database;
30
- JWT_SECRET: string;
31
- CLOUDFLARE_DATABASE_ID: string;
32
- CLOUDFLARE_D1_TOKEN: string;
33
- CLOUDFLARE_ACCOUNT_ID: string;
34
- ISSUER: string;
35
- GOOGLE_API_KEY: string;
36
- GOOGLE_SERVER_URL: string;
37
- GOOGLE_CLIENT_ID: string;
38
- GOOGLE_CLIENT_SECRET: string;
39
- FACEBOOK_SERVER_URL: string;
40
- FACEBOOK_CLIENT_ID: string;
41
- FACEBOOK_CLIENT_SECRET: string;
42
- OAUTH_REDIRECT_URI: string;
43
- ASTROLOGY_API_USER: string;
44
- ASTROLOGY_API_KEY: string;
45
-
46
- API_BASE_URL: string;
47
- PUBLIC_GOOGLE_CLIENT_ID: string;
48
- PUBLIC_FACEBOOK_CLIENT_ID: string;
49
- PUBLIC_APP_NAME: string;
50
- PUBLIC_APP_VERSION: string;
51
- PUBLIC_ANALYTICS_ID?: string;
52
- };
53
-
54
- export type Variables = {
55
- jwtPayload: {
56
- userId: string;
57
- email?: string;
58
- roles?: string[];
59
- };
60
- };
61
-
62
- export type BackendBindings = Env &
63
- Pick<
64
- CentralBindings,
65
- | 'TEST_IMAGES_BUCKET'
66
- | 'PHOTOS_BUCKET'
67
- | 'OPENAI_API_KEY'
68
- | 'LEONARDO_API_KEY'
69
- | 'DESCRIBER_API_KEY'
70
- | 'DESCRIBER_APP_ID'
71
- | 'AKOOL_API_KEY'
72
- | 'KV_GENERATION_MANAGEMENT'
73
- | 'KV_USER_GENERATIONS'
74
- | 'KV_ARCHETYPES'
75
- | 'KV_LEONARDO_PROMPTS'
76
- | 'PROMPT_IMAGE_DESCRIBER'
77
- | 'PROMPT_GENERATE_ARCHETYPE'
78
- | 'PROMPT_GENERATE_LEONARDO'
79
- | 'NEGATIVE_PROMPT_LEONARDO'
80
- | 'PROMPT_GENERATE_USER_LUMINOUS_SELF'
81
- | 'DB'
82
- | 'JWT_SECRET'
83
- | 'GOOGLE_API_KEY'
84
- | 'GOOGLE_SERVER_URL'
85
- | 'GOOGLE_CLIENT_ID'
86
- | 'GOOGLE_CLIENT_SECRET'
87
- | 'FACEBOOK_SERVER_URL'
88
- | 'FACEBOOK_CLIENT_ID'
89
- | 'FACEBOOK_CLIENT_SECRET'
90
- | 'OAUTH_REDIRECT_URI'
91
- | 'ASTROLOGY_API_USER'
92
- | 'ASTROLOGY_API_KEY'
93
- | 'AI'
94
- >;
95
-
96
- export type BackendCtx = Context<
97
- {
98
- Bindings: BackendBindings;
99
- Variables: Variables;
100
- },
101
- any,
102
- {}
103
- >;
104
-
105
- export type FrontendBindings = Pick<
106
- CentralBindings,
107
- | 'API_BASE_URL'
108
- | 'PUBLIC_GOOGLE_CLIENT_ID'
109
- | 'PUBLIC_FACEBOOK_CLIENT_ID'
110
- | 'PUBLIC_APP_NAME'
111
- | 'PUBLIC_APP_VERSION'
112
- | 'PUBLIC_ANALYTICS_ID'
113
- >;
114
-
115
- export type FrontCtx = {
116
- bindings: FrontendBindings;
117
- };
118
-
119
- export type AuthBindings = Env &
120
- Pick<
121
- CentralBindings,
122
- | 'JWT_SECRET'
123
- | 'GOOGLE_CLIENT_ID'
124
- | 'GOOGLE_CLIENT_SECRET'
125
- | 'GOOGLE_SERVER_URL'
126
- | 'FACEBOOK_CLIENT_ID'
127
- | 'FACEBOOK_CLIENT_SECRET'
128
- | 'FACEBOOK_SERVER_URL'
129
- | 'OAUTH_REDIRECT_URI'
130
- | 'ISSUER'
131
- >;
132
-
133
- export type AuthCtx = {
134
- bindings: AuthBindings;
135
- variables: Variables;
136
- };
137
-
138
- export type Bindings = Env & {
139
- TEST_IMAGES_BUCKET: R2Bucket;
140
- PHOTOS_BUCKET: R2Bucket;
141
- OPENAI_API_KEY: string;
142
- LEONARDO_API_KEY: string;
143
- DESCRIBER_API_KEY: string;
144
- DESCRIBER_APP_ID: string;
145
- AKOOL_API_KEY: string;
146
- KV_GENERATION_MANAGEMENT: KVNamespace;
147
- KV_USER_GENERATIONS: KVNamespace;
148
- KV_ARCHETYPES: KVNamespace;
149
- KV_LEONARDO_PROMPTS: KVNamespace;
150
- KV_TEST: KVNamespace;
151
- PROMPT_IMAGE_DESCRIBER: string;
152
- PROMPT_GENERATE_ARCHETYPE: string;
153
- PROMPT_GENERATE_LEONARDO: string;
154
- NEGATIVE_PROMPT_LEONARDO: string;
155
- PROMPT_GENERATE_USER_LUMINOUS_SELF: string;
156
- AI: Ai;
157
- DB: D1Database;
158
- JWT_SECRET: string;
159
- CLOUDFLARE_DATABASE_ID: string;
160
- CLOUDFLARE_D1_TOKEN: string;
161
- CLOUDFLARE_ACCOUNT_ID: string;
162
- ISSUER: string;
163
- GOOGLE_API_KEY: string;
164
- GOOGLE_SERVER_URL: string;
165
- GOOGLE_CLIENT_ID: string;
166
- GOOGLE_CLIENT_SECRET: string;
167
- FACEBOOK_SERVER_URL: string;
168
- FACEBOOK_CLIENT_ID: string;
169
- FACEBOOK_CLIENT_SECRET: string;
170
- OAUTH_REDIRECT_URI: string;
171
- ASTROLOGY_API_USER: string;
172
- ASTROLOGY_API_KEY: string;
173
- };
174
-
175
- export type Ctx = Context<
176
- {
177
- Bindings: Bindings;
178
- Variables: Variables;
179
- },
180
- any,
181
- {}
182
- >;
183
-
184
- export type Provider = 'google' | 'facebook';
185
-
186
- export type ProviderInfo = {
187
- serverUrl: string;
188
- clientId: string;
189
- clientSecret: string;
190
- resourceUrl: string;
191
- };
192
-
193
- export const VALID_GENDERS_ARRAY = ['male', 'female', 'non-binary'] as const;
194
-
195
- export type Gender = (typeof VALID_GENDERS_ARRAY)[number];
196
-
197
- export const VALID_GENDERS = new Set<Gender>(VALID_GENDERS_ARRAY);
1
+ export * from './backend';
2
+ export * from './frontend';
@@ -0,0 +1,192 @@
1
+ import {
2
+ Ai,
3
+ D1Database,
4
+ KVNamespace,
5
+ R2Bucket,
6
+ } from '@cloudflare/workers-types';
7
+ import { Context, Env } from 'hono';
8
+
9
+ export type CentralBindings = {
10
+ TEST_IMAGES_BUCKET: R2Bucket;
11
+ PHOTOS_BUCKET: R2Bucket;
12
+ OPENAI_API_KEY: string;
13
+ LEONARDO_API_KEY: string;
14
+ DESCRIBER_API_KEY: string;
15
+ DESCRIBER_APP_ID: string;
16
+ AKOOL_API_KEY: string;
17
+ KV_GENERATION_MANAGEMENT: KVNamespace;
18
+ KV_USER_GENERATIONS: KVNamespace;
19
+ KV_ARCHETYPES: KVNamespace;
20
+ KV_LEONARDO_PROMPTS: KVNamespace;
21
+ KV_TEST: KVNamespace;
22
+ PROMPT_IMAGE_DESCRIBER: string;
23
+ PROMPT_GENERATE_ARCHETYPE: string;
24
+ PROMPT_GENERATE_LEONARDO: string;
25
+ NEGATIVE_PROMPT_LEONARDO: string;
26
+ PROMPT_GENERATE_USER_LUMINOUS_SELF: string;
27
+ AI: Ai;
28
+ DB: D1Database;
29
+ JWT_SECRET: string;
30
+ CLOUDFLARE_DATABASE_ID: string;
31
+ CLOUDFLARE_D1_TOKEN: string;
32
+ CLOUDFLARE_ACCOUNT_ID: string;
33
+ ISSUER: string;
34
+ GOOGLE_API_KEY: string;
35
+ GOOGLE_SERVER_URL: string;
36
+ GOOGLE_CLIENT_ID: string;
37
+ GOOGLE_CLIENT_SECRET: string;
38
+ FACEBOOK_SERVER_URL: string;
39
+ FACEBOOK_CLIENT_ID: string;
40
+ FACEBOOK_CLIENT_SECRET: string;
41
+ OAUTH_REDIRECT_URI: string;
42
+ ASTROLOGY_API_USER: string;
43
+ ASTROLOGY_API_KEY: string;
44
+
45
+ API_BASE_URL: string;
46
+ PUBLIC_GOOGLE_CLIENT_ID: string;
47
+ PUBLIC_FACEBOOK_CLIENT_ID: string;
48
+ PUBLIC_APP_NAME: string;
49
+ PUBLIC_APP_VERSION: string;
50
+ PUBLIC_ANALYTICS_ID?: string;
51
+ };
52
+
53
+ export type Variables = {
54
+ jwtPayload: {
55
+ userId: string;
56
+ email?: string;
57
+ roles?: string[];
58
+ };
59
+ };
60
+
61
+ export type BackendBindings = Env &
62
+ Pick<
63
+ CentralBindings,
64
+ | 'TEST_IMAGES_BUCKET'
65
+ | 'PHOTOS_BUCKET'
66
+ | 'OPENAI_API_KEY'
67
+ | 'LEONARDO_API_KEY'
68
+ | 'DESCRIBER_API_KEY'
69
+ | 'DESCRIBER_APP_ID'
70
+ | 'AKOOL_API_KEY'
71
+ | 'KV_GENERATION_MANAGEMENT'
72
+ | 'KV_USER_GENERATIONS'
73
+ | 'KV_ARCHETYPES'
74
+ | 'KV_LEONARDO_PROMPTS'
75
+ | 'PROMPT_IMAGE_DESCRIBER'
76
+ | 'PROMPT_GENERATE_ARCHETYPE'
77
+ | 'PROMPT_GENERATE_LEONARDO'
78
+ | 'NEGATIVE_PROMPT_LEONARDO'
79
+ | 'PROMPT_GENERATE_USER_LUMINOUS_SELF'
80
+ | 'DB'
81
+ | 'JWT_SECRET'
82
+ | 'GOOGLE_API_KEY'
83
+ | 'GOOGLE_SERVER_URL'
84
+ | 'GOOGLE_CLIENT_ID'
85
+ | 'GOOGLE_CLIENT_SECRET'
86
+ | 'FACEBOOK_SERVER_URL'
87
+ | 'FACEBOOK_CLIENT_ID'
88
+ | 'FACEBOOK_CLIENT_SECRET'
89
+ | 'OAUTH_REDIRECT_URI'
90
+ | 'ASTROLOGY_API_USER'
91
+ | 'ASTROLOGY_API_KEY'
92
+ | 'AI'
93
+ >;
94
+
95
+ export type BackendCtx = Context<
96
+ {
97
+ Bindings: BackendBindings;
98
+ Variables: Variables;
99
+ },
100
+ any,
101
+ {}
102
+ >;
103
+
104
+ export type FrontendBindings = Pick<
105
+ CentralBindings,
106
+ | 'API_BASE_URL'
107
+ | 'PUBLIC_GOOGLE_CLIENT_ID'
108
+ | 'PUBLIC_FACEBOOK_CLIENT_ID'
109
+ | 'PUBLIC_APP_NAME'
110
+ | 'PUBLIC_APP_VERSION'
111
+ | 'PUBLIC_ANALYTICS_ID'
112
+ >;
113
+
114
+ export type FrontCtx = Context<
115
+ {
116
+ Bindings: FrontendBindings;
117
+ Variables: Variables;
118
+ },
119
+ any,
120
+ {}
121
+ >;
122
+
123
+ export type AuthBindings = Env &
124
+ Pick<
125
+ CentralBindings,
126
+ | 'JWT_SECRET'
127
+ | 'GOOGLE_CLIENT_ID'
128
+ | 'GOOGLE_CLIENT_SECRET'
129
+ | 'GOOGLE_SERVER_URL'
130
+ | 'FACEBOOK_CLIENT_ID'
131
+ | 'FACEBOOK_CLIENT_SECRET'
132
+ | 'FACEBOOK_SERVER_URL'
133
+ | 'OAUTH_REDIRECT_URI'
134
+ | 'ISSUER'
135
+ | 'DB'
136
+ | 'CLOUDFLARE_ACCOUNT_ID'
137
+ >;
138
+
139
+ export type AuthCtx = Context<
140
+ {
141
+ Bindings: AuthBindings;
142
+ Variables: Variables;
143
+ },
144
+ any,
145
+ {}
146
+ >;
147
+
148
+ export type Bindings = Env & {
149
+ TEST_IMAGES_BUCKET: R2Bucket;
150
+ PHOTOS_BUCKET: R2Bucket;
151
+ OPENAI_API_KEY: string;
152
+ LEONARDO_API_KEY: string;
153
+ DESCRIBER_API_KEY: string;
154
+ DESCRIBER_APP_ID: string;
155
+ AKOOL_API_KEY: string;
156
+ KV_GENERATION_MANAGEMENT: KVNamespace;
157
+ KV_USER_GENERATIONS: KVNamespace;
158
+ KV_ARCHETYPES: KVNamespace;
159
+ KV_LEONARDO_PROMPTS: KVNamespace;
160
+ KV_TEST: KVNamespace;
161
+ PROMPT_IMAGE_DESCRIBER: string;
162
+ PROMPT_GENERATE_ARCHETYPE: string;
163
+ PROMPT_GENERATE_LEONARDO: string;
164
+ NEGATIVE_PROMPT_LEONARDO: string;
165
+ PROMPT_GENERATE_USER_LUMINOUS_SELF: string;
166
+ AI: Ai;
167
+ DB: D1Database;
168
+ JWT_SECRET: string;
169
+ CLOUDFLARE_DATABASE_ID: string;
170
+ CLOUDFLARE_D1_TOKEN: string;
171
+ CLOUDFLARE_ACCOUNT_ID: string;
172
+ ISSUER: string;
173
+ GOOGLE_API_KEY: string;
174
+ GOOGLE_SERVER_URL: string;
175
+ GOOGLE_CLIENT_ID: string;
176
+ GOOGLE_CLIENT_SECRET: string;
177
+ FACEBOOK_SERVER_URL: string;
178
+ FACEBOOK_CLIENT_ID: string;
179
+ FACEBOOK_CLIENT_SECRET: string;
180
+ OAUTH_REDIRECT_URI: string;
181
+ ASTROLOGY_API_USER: string;
182
+ ASTROLOGY_API_KEY: string;
183
+ };
184
+
185
+ export type Ctx = Context<
186
+ {
187
+ Bindings: Bindings;
188
+ Variables: Variables;
189
+ },
190
+ any,
191
+ {}
192
+ >;
@@ -1,5 +1,11 @@
1
1
  import type { InferInsertModel, InferSelectModel, Table } from 'drizzle-orm';
2
- import { users, astrologicalData, generations, products, tokens } from '../db/schema';
2
+ import {
3
+ astrologicalData,
4
+ generations,
5
+ products,
6
+ tokens,
7
+ users,
8
+ } from '../../db/schema';
3
9
 
4
10
  type NullableSelect<T extends Table> = InferSelectModel<T> | undefined | null;
5
11
 
@@ -0,0 +1,14 @@
1
+ export type Provider = 'google' | 'facebook';
2
+
3
+ export type ProviderInfo = {
4
+ serverUrl: string;
5
+ clientId: string;
6
+ clientSecret: string;
7
+ resourceUrl: string;
8
+ };
9
+
10
+ export const VALID_GENDERS_ARRAY = ['male', 'female', 'non-binary'] as const;
11
+
12
+ export type Gender = (typeof VALID_GENDERS_ARRAY)[number];
13
+
14
+ export const VALID_GENDERS = new Set<Gender>(VALID_GENDERS_ARRAY);
package/utils/index.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { jwtVerify } from 'jose';
2
- import { Ctx, Provider, ProviderInfo } from '../types';
2
+ import { AuthCtx, Provider, ProviderInfo } from '../types';
3
3
 
4
4
  export const verifyToken = async (
5
- c: Ctx,
5
+ c: AuthCtx,
6
6
  token: string
7
7
  ): Promise<{ userId: string; email?: string; roles?: string[] }> => {
8
8
  const jwtSecret = c.env.JWT_SECRET;
@@ -32,7 +32,9 @@ export const verifyToken = async (
32
32
  }
33
33
  };
34
34
 
35
- export const providers: (c: Ctx) => Record<Provider, ProviderInfo> = (c) => ({
35
+ export const providers: (c: AuthCtx) => Record<Provider, ProviderInfo> = (
36
+ c
37
+ ) => ({
36
38
  google: {
37
39
  serverUrl: c.env.GOOGLE_SERVER_URL,
38
40
  clientId: c.env.GOOGLE_CLIENT_ID,