@pack/hydrogen 0.0.2 → 0.0.3
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.
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import { type ActionFunction, type LoaderFunction } from "@shopify/remix-oxygen";
|
|
2
|
+
type JsonFunction = <Data>(data: Data, init?: number | ResponseInit) => TypedResponse<Data>;
|
|
3
|
+
type RedirectFunction = (url: string, init?: number | ResponseInit) => Response;
|
|
4
|
+
type TypedResponse<T = unknown> = Omit<Response, "json"> & {
|
|
5
|
+
json(): Promise<T>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* This is a shortcut for creating `application/json` responses. Converts `data`
|
|
9
|
+
* to JSON and sets the `Content-Type` header.
|
|
10
|
+
*/
|
|
11
|
+
export declare const json: JsonFunction;
|
|
12
|
+
/**
|
|
13
|
+
* A redirect response. Sets the status code and the `Location` header.
|
|
14
|
+
* Defaults to "302 Found".
|
|
15
|
+
*/
|
|
16
|
+
export declare const redirect: RedirectFunction;
|
|
2
17
|
/**
|
|
3
18
|
* A `POST` request to this route will exit preview mode
|
|
4
19
|
* POST /api/edit Content-Type: application/x-www-form-urlencoded
|
|
@@ -8,4 +23,5 @@ export declare const action: ActionFunction;
|
|
|
8
23
|
* A `GET` request to this route will enter preview mode
|
|
9
24
|
*/
|
|
10
25
|
export declare const loader: LoaderFunction;
|
|
26
|
+
export {};
|
|
11
27
|
//# sourceMappingURL=preview-mode.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview-mode.d.ts","sourceRoot":"","sources":["../../src/preview/preview-mode.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"preview-mode.d.ts","sourceRoot":"","sources":["../../src/preview/preview-mode.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAI/B,KAAK,YAAY,GAAG,CAAC,IAAI,EACvB,IAAI,EAAE,IAAI,EACV,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,KACzB,aAAa,CAAC,IAAI,CAAC,CAAC;AAEzB,KAAK,gBAAgB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,YAAY,KAAK,QAAQ,CAAC;AAIhF,KAAK,aAAa,CAAC,CAAC,GAAG,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG;IACzD,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,YAYlB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,QAAQ,EAAE,gBAetB,CAAC;AAoBF;;;GAGG;AACH,eAAO,MAAM,MAAM,EAAE,cAkBpB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,MAAM,EAAE,cA+BpB,CAAC"}
|
|
@@ -1,5 +1,38 @@
|
|
|
1
|
-
import { json, redirect, } from "@shopify/remix-oxygen";
|
|
2
1
|
const ROOT_PATH = "/";
|
|
2
|
+
/**
|
|
3
|
+
* This is a shortcut for creating `application/json` responses. Converts `data`
|
|
4
|
+
* to JSON and sets the `Content-Type` header.
|
|
5
|
+
*/
|
|
6
|
+
export const json = (data, init = {}) => {
|
|
7
|
+
let responseInit = typeof init === "number" ? { status: init } : init;
|
|
8
|
+
let headers = new Headers(responseInit.headers);
|
|
9
|
+
if (!headers.has("Content-Type")) {
|
|
10
|
+
headers.set("Content-Type", "application/json; charset=utf-8");
|
|
11
|
+
}
|
|
12
|
+
return new Response(JSON.stringify(data), {
|
|
13
|
+
...responseInit,
|
|
14
|
+
headers,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* A redirect response. Sets the status code and the `Location` header.
|
|
19
|
+
* Defaults to "302 Found".
|
|
20
|
+
*/
|
|
21
|
+
export const redirect = (url, init = 302) => {
|
|
22
|
+
let responseInit = init;
|
|
23
|
+
if (typeof responseInit === "number") {
|
|
24
|
+
responseInit = { status: responseInit };
|
|
25
|
+
}
|
|
26
|
+
else if (typeof responseInit.status === "undefined") {
|
|
27
|
+
responseInit.status = 302;
|
|
28
|
+
}
|
|
29
|
+
let headers = new Headers(responseInit.headers);
|
|
30
|
+
headers.set("Location", url);
|
|
31
|
+
return new Response(null, {
|
|
32
|
+
...responseInit,
|
|
33
|
+
headers,
|
|
34
|
+
});
|
|
35
|
+
};
|
|
3
36
|
/**
|
|
4
37
|
* A not found response. Sets the status code.
|
|
5
38
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pack/hydrogen",
|
|
3
3
|
"description": "Pack Hydrogen",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
7
7
|
"engines": {
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@pack/client": "^0.0.5",
|
|
26
|
-
"@shopify/hydrogen": "^2023.10.2"
|
|
27
|
-
"@shopify/remix-oxygen": "^2.0.1"
|
|
26
|
+
"@shopify/hydrogen": "^2023.10.2"
|
|
28
27
|
},
|
|
29
28
|
"devDependencies": {
|
|
30
|
-
"@shopify/oxygen-workers-types": "^4.0.0"
|
|
29
|
+
"@shopify/oxygen-workers-types": "^4.0.0",
|
|
30
|
+
"@shopify/remix-oxygen": "^2.0.1"
|
|
31
31
|
}
|
|
32
32
|
}
|