@promptlycms/prompts 0.0.1 → 0.1.0-canary.507f155

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/README.md CHANGED
@@ -1,45 +1,2 @@
1
- # @promptlycms/prompts
2
-
3
- ## ⚠️ IMPORTANT NOTICE ⚠️
4
-
5
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
6
-
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
8
-
9
- ## Purpose
10
-
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `@promptlycms/prompts`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
14
- 3. Establish provenance for packages published under this name
15
-
16
- ## What is OIDC Trusted Publishing?
17
-
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
19
-
20
- ## Setup Instructions
21
-
22
- To properly configure OIDC trusted publishing for this package:
23
-
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
28
-
29
- ## DO NOT USE THIS PACKAGE
30
-
31
- This package is a placeholder for OIDC configuration only. It:
32
- - Contains no executable code
33
- - Provides no functionality
34
- - Should not be installed as a dependency
35
- - Exists only for administrative purposes
36
-
37
- ## More Information
38
-
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
42
-
43
- ---
44
-
45
- **Maintained for OIDC setup purposes only**
1
+ # promptly-package
2
+ NPM package for PromptlyCMS
@@ -0,0 +1,284 @@
1
+ // src/schema/builder.ts
2
+ import { z } from "zod";
3
+ var resolveTypeString = (typeStr) => {
4
+ const builder = TYPE_BUILDERS.get(typeStr);
5
+ if (builder) {
6
+ return builder({
7
+ id: "",
8
+ name: "",
9
+ type: typeStr,
10
+ validations: [],
11
+ params: {}
12
+ });
13
+ }
14
+ return z.string();
15
+ };
16
+ var buildCoercible = (params, coerced, standard) => {
17
+ if (params.coerce) {
18
+ return coerced;
19
+ }
20
+ return standard;
21
+ };
22
+ var TYPE_BUILDERS = /* @__PURE__ */ new Map([
23
+ ["string", (f) => buildCoercible(f.params, z.coerce.string(), z.string())],
24
+ ["number", (f) => buildCoercible(f.params, z.coerce.number(), z.number())],
25
+ ["boolean", (f) => buildCoercible(f.params, z.coerce.boolean(), z.boolean())],
26
+ ["date", (f) => buildCoercible(f.params, z.coerce.date(), z.date())],
27
+ ["bigint", (f) => buildCoercible(f.params, z.coerce.bigint(), z.bigint())],
28
+ ["null", () => z.null()],
29
+ ["undefined", () => z.undefined()],
30
+ ["void", () => z.void()],
31
+ ["any", () => z.any()],
32
+ ["unknown", () => z.unknown()],
33
+ ["never", () => z.never()],
34
+ ["nan", () => z.nan()],
35
+ ["symbol", () => z.symbol()],
36
+ [
37
+ "enum",
38
+ (f) => {
39
+ const values = f.params.enumValues ?? [];
40
+ return z.enum(values);
41
+ }
42
+ ],
43
+ [
44
+ "literal",
45
+ (f) => {
46
+ const value = f.params.enumValues?.[0] ?? "";
47
+ return z.literal(value);
48
+ }
49
+ ],
50
+ [
51
+ "array",
52
+ (f) => {
53
+ if (f.params.isTuple && f.params.tupleTypes) {
54
+ const types = f.params.tupleTypes.map(resolveTypeString);
55
+ return z.tuple(types);
56
+ }
57
+ const elementSchema = f.params.elementType ? resolveTypeString(f.params.elementType) : z.unknown();
58
+ return z.array(elementSchema);
59
+ }
60
+ ],
61
+ [
62
+ "object",
63
+ (f) => {
64
+ const schema = z.object({});
65
+ if (f.params.isStrict) {
66
+ return schema.strict();
67
+ }
68
+ if (f.params.isPassthrough) {
69
+ return schema.passthrough();
70
+ }
71
+ return schema;
72
+ }
73
+ ],
74
+ [
75
+ "record",
76
+ (f) => {
77
+ const keySchema = f.params.keyType ? resolveTypeString(f.params.keyType) : z.string();
78
+ const valueSchema = f.params.valueType ? resolveTypeString(f.params.valueType) : z.unknown();
79
+ return z.record(keySchema, valueSchema);
80
+ }
81
+ ],
82
+ [
83
+ "map",
84
+ (f) => {
85
+ const keySchema = f.params.keyType ? resolveTypeString(f.params.keyType) : z.string();
86
+ const valueSchema = f.params.valueType ? resolveTypeString(f.params.valueType) : z.unknown();
87
+ return z.map(keySchema, valueSchema);
88
+ }
89
+ ],
90
+ [
91
+ "set",
92
+ (f) => {
93
+ const elementSchema = f.params.elementType ? resolveTypeString(f.params.elementType) : z.unknown();
94
+ return z.set(elementSchema);
95
+ }
96
+ ],
97
+ [
98
+ "union",
99
+ (f) => {
100
+ if (f.params.isDiscriminatedUnion && f.params.discriminatedUnion) {
101
+ const { discriminator, cases } = f.params.discriminatedUnion;
102
+ const schemas = Object.values(cases).map(
103
+ (c) => z.object({
104
+ [discriminator]: z.literal(c.value),
105
+ ...Object.fromEntries(
106
+ c.fields.map((field) => [field.name, buildFieldSchema(field)])
107
+ )
108
+ })
109
+ );
110
+ return z.discriminatedUnion(
111
+ discriminator,
112
+ schemas
113
+ );
114
+ }
115
+ const types = (f.params.unionTypes ?? []).map(resolveTypeString);
116
+ return z.union(types);
117
+ }
118
+ ],
119
+ [
120
+ "intersection",
121
+ (f) => {
122
+ const types = (f.params.unionTypes ?? []).map(resolveTypeString);
123
+ return z.intersection(types[0] ?? z.unknown(), types[1] ?? z.unknown());
124
+ }
125
+ ]
126
+ ]);
127
+ var coerceDefaultValue = (value, fieldType) => {
128
+ const coercers = /* @__PURE__ */ new Map([
129
+ ["number", (v) => Number(v)],
130
+ ["boolean", (v) => v === "true"],
131
+ ["bigint", (v) => BigInt(v)]
132
+ ]);
133
+ const coercer = coercers.get(fieldType);
134
+ if (coercer) {
135
+ return coercer(value);
136
+ }
137
+ return value;
138
+ };
139
+ var applySizeValidation = (schema, type, value, message) => {
140
+ const num = Number(value);
141
+ if (schema instanceof z.ZodString) {
142
+ const methods = {
143
+ min: (n, m) => schema.min(n, m),
144
+ max: (n, m) => schema.max(n, m),
145
+ length: (n, m) => schema.length(n, m)
146
+ };
147
+ return methods[type]?.(num, message) ?? schema;
148
+ }
149
+ if (schema instanceof z.ZodNumber) {
150
+ const methods = {
151
+ min: (n, m) => schema.min(n, m),
152
+ max: (n, m) => schema.max(n, m)
153
+ };
154
+ return methods[type]?.(num, message) ?? schema;
155
+ }
156
+ if (schema instanceof z.ZodArray) {
157
+ const methods = {
158
+ min: (n) => schema.min(n),
159
+ max: (n) => schema.max(n),
160
+ length: (n) => schema.length(n)
161
+ };
162
+ return methods[type]?.(num) ?? schema;
163
+ }
164
+ return schema;
165
+ };
166
+ var VALIDATION_APPLICATORS = /* @__PURE__ */ new Map([
167
+ // Size validations
168
+ ["min", (s, r) => applySizeValidation(s, "min", r.value, r.message)],
169
+ ["max", (s, r) => applySizeValidation(s, "max", r.value, r.message)],
170
+ ["length", (s, r) => applySizeValidation(s, "length", r.value, r.message)],
171
+ // String validations
172
+ ["email", (s, r) => s instanceof z.ZodString ? s.email(r.message) : s],
173
+ ["url", (s, r) => s instanceof z.ZodString ? s.url(r.message) : s],
174
+ ["uuid", (s, r) => s instanceof z.ZodString ? s.uuid(r.message) : s],
175
+ ["cuid", (s, r) => s instanceof z.ZodString ? s.cuid(r.message) : s],
176
+ ["cuid2", (s, r) => s instanceof z.ZodString ? s.cuid2(r.message) : s],
177
+ ["ulid", (s, r) => s instanceof z.ZodString ? s.ulid(r.message) : s],
178
+ [
179
+ "regex",
180
+ (s, r) => s instanceof z.ZodString ? s.regex(new RegExp(r.value), r.message) : s
181
+ ],
182
+ [
183
+ "startsWith",
184
+ (s, r) => s instanceof z.ZodString ? s.startsWith(r.value, r.message) : s
185
+ ],
186
+ [
187
+ "endsWith",
188
+ (s, r) => s instanceof z.ZodString ? s.endsWith(r.value, r.message) : s
189
+ ],
190
+ [
191
+ "datetime",
192
+ (s, _r, f) => {
193
+ if (!(s instanceof z.ZodString)) {
194
+ return s;
195
+ }
196
+ const opts = f.params.stringOptions?.datetime;
197
+ return s.datetime(opts);
198
+ }
199
+ ],
200
+ [
201
+ "ip",
202
+ (s, _r, f) => {
203
+ if (!(s instanceof z.ZodString)) {
204
+ return s;
205
+ }
206
+ const version = f.params.stringOptions?.ip?.version;
207
+ if (version === "v6") {
208
+ return s.ipv6();
209
+ }
210
+ return s.ipv4();
211
+ }
212
+ ],
213
+ // String transforms
214
+ ["trim", (s) => s instanceof z.ZodString ? s.trim() : s],
215
+ ["toLowerCase", (s) => s instanceof z.ZodString ? s.toLowerCase() : s],
216
+ ["toUpperCase", (s) => s instanceof z.ZodString ? s.toUpperCase() : s],
217
+ // Number validations
218
+ ["int", (s, r) => s instanceof z.ZodNumber ? s.int(r.message) : s],
219
+ [
220
+ "positive",
221
+ (s, r) => s instanceof z.ZodNumber ? s.positive(r.message) : s
222
+ ],
223
+ [
224
+ "negative",
225
+ (s, r) => s instanceof z.ZodNumber ? s.negative(r.message) : s
226
+ ],
227
+ [
228
+ "multipleOf",
229
+ (s, r) => s instanceof z.ZodNumber ? s.multipleOf(Number(r.value), r.message) : s
230
+ ],
231
+ ["finite", (s, r) => s instanceof z.ZodNumber ? s.finite(r.message) : s],
232
+ ["safe", (s, r) => s instanceof z.ZodNumber ? s.safe(r.message) : s],
233
+ // Collection
234
+ [
235
+ "nonempty",
236
+ (s) => {
237
+ if (s instanceof z.ZodString) {
238
+ return s.min(1);
239
+ }
240
+ if (s instanceof z.ZodArray) {
241
+ return s.nonempty();
242
+ }
243
+ return s;
244
+ }
245
+ ],
246
+ // Wrapping modifiers
247
+ ["optional", (s) => s.optional()],
248
+ ["nullable", (s) => s.nullable()],
249
+ ["nullish", (s) => s.nullish()],
250
+ // Default & catch
251
+ ["default", (s, r, f) => s.default(coerceDefaultValue(r.value, f.type))],
252
+ ["catch", (s, r, f) => s.catch(coerceDefaultValue(r.value, f.type))],
253
+ // Readonly
254
+ ["readonly", (s) => s.readonly()]
255
+ ]);
256
+ var buildFieldSchema = (field) => {
257
+ const builder = TYPE_BUILDERS.get(field.type);
258
+ if (!builder) {
259
+ return z.unknown();
260
+ }
261
+ let schema = builder(field);
262
+ for (const rule of field.validations) {
263
+ const applicator = VALIDATION_APPLICATORS.get(rule.type);
264
+ if (applicator) {
265
+ schema = applicator(schema, rule, field);
266
+ }
267
+ }
268
+ if (field.params.description) {
269
+ schema = schema.describe(field.params.description);
270
+ }
271
+ return schema;
272
+ };
273
+ var buildZodSchema = (fields) => {
274
+ const shape = {};
275
+ for (const field of fields) {
276
+ shape[field.name] = buildFieldSchema(field);
277
+ }
278
+ return z.object(shape);
279
+ };
280
+
281
+ export {
282
+ buildFieldSchema,
283
+ buildZodSchema
284
+ };