oc-server 3.0.0 → 3.1.1

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/cli/cli.js CHANGED
@@ -52,15 +52,35 @@ function cli() {
52
52
  }
53
53
  process.exit(0);
54
54
  }
55
- let template;
56
- try {
57
- template = require(`${templateType}-compiler/dist/lib/hmr`);
55
+ function tryRequire(name) {
56
+ try {
57
+ return { success: true, value: require(name) };
58
+ }
59
+ catch (e) {
60
+ return { success: false, value: e };
61
+ }
58
62
  }
59
- catch (e) {
60
- console.error(`The template ${templateType} is not supported. Try updating to the last version`);
63
+ const result = tryRequire(`${templateType}-compiler/dist/lib/hmr`);
64
+ if (!result.success) {
65
+ const code = String(result.value.code);
66
+ if (code === 'ERR_REQUIRE_ESM') {
67
+ console.error('You are using an older version of node that does not support ESM on require. Please update to the latest 22.x or higher');
68
+ }
69
+ else if (code === 'MODULE_NOT_FOUND') {
70
+ const baseResult = tryRequire(`${templateType}-compiler`);
71
+ if (baseResult.success) {
72
+ console.error(`The template ${templateType} is not supported. Try updating to the last version`);
73
+ }
74
+ else {
75
+ console.error(`Could not find the template compiler library: ${templateType}-compiler in your project`);
76
+ }
77
+ }
78
+ else {
79
+ console.error(result.value);
80
+ }
61
81
  process.exit(1);
62
82
  }
63
83
  if (command === 'dev') {
64
- (0, server_1.createServer)({ template, port });
84
+ (0, server_1.createServer)({ template: result.value, port });
65
85
  }
66
86
  }
package/dist/cli/index.js CHANGED
File without changes
package/dist/types.d.ts CHANGED
@@ -2,6 +2,14 @@ export type Prettify<T> = {
2
2
  [K in keyof T]: T[K];
3
3
  } & {};
4
4
  type JsonPrimitive = string | number | boolean | null | undefined;
5
+ type JsonObject = {
6
+ [key: string]: JsonPrimitive | JsonArray | JsonObject;
7
+ };
8
+ interface JsonArray extends Array<JsonPrimitive | JsonArray | JsonObject> {
9
+ }
10
+ interface JsonLike {
11
+ [key: string]: JsonPrimitive | JsonArray | JsonObject;
12
+ }
5
13
  type CleanNeverProperties<T> = {
6
14
  [K in keyof T as T[K] extends never ? never : K]: T[K];
7
15
  };
@@ -28,6 +36,36 @@ export interface Template {
28
36
  version: string;
29
37
  externals: External[];
30
38
  }
39
+ export interface CookieOptions {
40
+ /** Convenient option for setting the expiry time relative to the current time in **milliseconds**. */
41
+ maxAge?: number | undefined;
42
+ /** Indicates if the cookie should be signed. */
43
+ signed?: boolean | undefined;
44
+ /** Expiry date of the cookie in GMT. If not specified (undefined), creates a session cookie. */
45
+ expires?: Date | undefined;
46
+ /** Flags the cookie to be accessible only by the web server. */
47
+ httpOnly?: boolean | undefined;
48
+ /** Path for the cookie. Defaults to “/”. */
49
+ path?: string | undefined;
50
+ /** Domain name for the cookie. Defaults to the domain name of the app. */
51
+ domain?: string | undefined;
52
+ /** Marks the cookie to be used with HTTPS only. */
53
+ secure?: boolean | undefined;
54
+ /** A synchronous function used for cookie value encoding. Defaults to encodeURIComponent. */
55
+ encode?: ((val: string) => string) | undefined;
56
+ /**
57
+ * Value of the “SameSite” Set-Cookie attribute.
58
+ * @link https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1.
59
+ */
60
+ sameSite?: boolean | 'lax' | 'strict' | 'none' | undefined;
61
+ /**
62
+ * Value of the “Priority” Set-Cookie attribute.
63
+ * @link https://datatracker.ietf.org/doc/html/draft-west-cookie-priority-00#section-4.3
64
+ */
65
+ priority?: 'low' | 'medium' | 'high';
66
+ /** Marks the cookie to use partioned storage. */
67
+ partitioned?: boolean | undefined;
68
+ }
31
69
  export type DataContext<T = any, E = Env, P = any, S = unknown> = {
32
70
  action?: string;
33
71
  acceptLanguage: AcceptLanguage[];
@@ -39,6 +77,7 @@ export type DataContext<T = any, E = Env, P = any, S = unknown> = {
39
77
  requestIp: string;
40
78
  setEmptyResponse: () => void;
41
79
  setHeader: (header: string, value: string) => void;
80
+ setCookie: (name: string, value: string | JsonLike, options?: CookieOptions) => void;
42
81
  staticPath: string;
43
82
  templates: Template[];
44
83
  } & (S extends Record<string, unknown> ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-server",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",