Skip to content

Commit ed5e1e3

Browse files
author
wellingtonjr3873
committed
Merge branch 'main' of github.com:deco-cx/apps
2 parents 417f8ce + 89ce6a3 commit ed5e1e3

File tree

252 files changed

+22220
-1313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

252 files changed

+22220
-1313
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
/home/runner/.cache/deno/deps/https/deno.land
2929
- uses: denoland/setup-deno@v2
3030
with:
31-
deno-version: v2.x
31+
deno-version: v2.4.5
3232
- name: Bundle Apps
3333
run: deno run -A --lock=deno.lock --frozen=false --reload scripts/start.ts
3434

@@ -40,7 +40,7 @@ jobs:
4040
shell: bash
4141
run: |
4242
git status --porcelain
43-
if [[ $(git status --porcelain | wc -c) -eq 0 ]]; then
43+
if [[ $(git status --porcelain | wc -c) -ne 0 ]]; then
4444
echo "uncommitted changes detected"
4545
exit 1
4646
fi

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<hr/>
1+
<hr/>
2+
23
<a href="https://deco.cx/discord" target="_blank"><img alt="Discord" src="https://img.shields.io/discord/985687648595243068?label=Discord&color=7289da" /></a>
34
&nbsp;
45
![Build Status](https://github.com/deco-cx/apps/workflows/ci/badge.svg?event=push&branch=main)

algolia/loaders/product/list.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SearchResponse } from "npm:@algolia/client-search";
1+
import { SearchResponse } from "npm:@algolia/client-search@5.0.0";
22
import { Product } from "../../../commerce/types.ts";
33

44
import { AppContext } from "../../mod.ts";

algolia/loaders/product/listingPage.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SearchResponse } from "npm:@algolia/client-search";
1+
import { SearchResponse } from "npm:@algolia/client-search@5.0.0";
22
import { Filter, ProductListingPage } from "../../../commerce/types.ts";
33
import { AppContext } from "../../mod.ts";
44
import { replaceHighlight } from "../../utils/highlight.ts";
@@ -51,6 +51,11 @@ interface Props {
5151
* @default 0
5252
*/
5353
startingPage?: 0 | 1;
54+
55+
/**
56+
* @description Index Name
57+
*/
58+
indexName?: string;
5459
}
5560

5661
const getPageInfo = (
@@ -174,7 +179,7 @@ const loader = async (
174179
): Promise<ProductListingPage | null> => {
175180
const url = new URL(req.url);
176181
const { client } = ctx;
177-
const indexName = getIndex(url.searchParams.get("sort"));
182+
const indexName = props?.indexName ?? getIndex(url.searchParams.get("sort"));
178183
const startingPage = props.startingPage ?? 0;
179184
const pageIndex = Number(url.searchParams.get("page")) || startingPage;
180185

@@ -191,9 +196,11 @@ const loader = async (
191196
// different categories are split by an AND. e.g.:
192197
//
193198
// (department:"man" OR department:"woman") AND (brand:"deco") AND (available:"true")
194-
const fFilters = facetFilters.map(([key, values]) =>
195-
`(${values.map((value) => `${key}:"${value}"`).join(" OR ")})`
196-
).join(" AND ");
199+
const fFilters = facetFilters
200+
.map(([key, values]) =>
201+
`(${values.map((value) => `${key}:"${value}"`).join(" OR ")})`
202+
)
203+
.join(" AND ");
197204

198205
const { results } = await client.search([
199206
{

algolia/loaders/product/suggestions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { SearchResponse } from "npm:@algolia/client-search";
1+
import type { SearchResponse } from "npm:@algolia/client-search@5.0.0";
22
import { Suggestion } from "../../../commerce/types.ts";
33
import type { AppContext } from "../../mod.ts";
44
import { replaceHighlight } from "../../utils/highlight.ts";

apify/actions/runActor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export interface Props {
3636
* @name RUN_ACTOR
3737
* @title Run Actor
3838
* @description Run an Apify actor synchronously and return dataset items
39+
* @deprecated Use RUN_ACTOR_V2 instead
3940
*/
4041
export default async function runActor(
4142
props: Props,

apify/actions/runActorAsync.ts

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { AppContext } from "../mod.ts";
2+
import { ActorRun } from "../utils/types.ts";
3+
4+
export interface Props {
5+
/**
6+
* @title Actor ID
7+
* @description The ID of the actor to run
8+
*/
9+
actorId: string;
10+
11+
/**
12+
* @title Input
13+
* @description Input data for the actor run (Stringified JSON object). If you don't know what object to pass, use an empty object: {}
14+
*/
15+
input: string;
16+
17+
/**
18+
* @title Timeout (seconds)
19+
* @description Maximum timeout for the run in seconds
20+
*/
21+
timeout?: number;
22+
23+
/**
24+
* @title Memory (MB)
25+
* @description Amount of memory allocated for the run in megabytes
26+
*/
27+
memory?: number;
28+
29+
/**
30+
* @title Build
31+
* @description Specific build version to use (optional)
32+
*/
33+
build?: string;
34+
}
35+
36+
/**
37+
* @name RUN_ACTOR_ASYNC
38+
* @title Run Actor Async
39+
* @description Run an Apify actor asynchronously and return immediately without waiting for completion
40+
*/
41+
export default async function runActorAsync(
42+
props: Props,
43+
_req: Request,
44+
ctx: AppContext,
45+
): Promise<
46+
{ data: ActorRun; error: null } | {
47+
error: string;
48+
data: null;
49+
}
50+
> {
51+
try {
52+
const { actorId, timeout, memory, build } = props;
53+
54+
if (!actorId) {
55+
return { error: "Actor ID is required", data: null };
56+
}
57+
58+
// Build query parameters
59+
const searchParams = new URLSearchParams();
60+
if (timeout !== undefined) {
61+
searchParams.set("timeout", timeout.toString());
62+
}
63+
if (memory !== undefined) {
64+
searchParams.set("memory", memory.toString());
65+
}
66+
if (build !== undefined) {
67+
searchParams.set("build", build);
68+
}
69+
70+
const response = await ctx.api["POST /v2/acts/:actorId/runs"]({
71+
actorId,
72+
...(searchParams.toString() ? { searchParams } : {}),
73+
});
74+
75+
if (!response.ok) {
76+
const errorText = await response.text();
77+
throw new Error(`HTTP ${response.status}: ${errorText}`);
78+
}
79+
80+
const result = await response.json();
81+
return { data: result, error: null };
82+
} catch (error) {
83+
console.error("Error starting actor run:", error);
84+
return {
85+
error: ctx.errorHandler.toHttpError(error, "Error starting actor run"),
86+
data: null,
87+
};
88+
}
89+
}

apify/actions/runActorV2.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { AppContext } from "../mod.ts";
2+
3+
export interface Props {
4+
/**
5+
* @title Actor ID
6+
* @description The ID of the actor to run
7+
*/
8+
actorId: string;
9+
10+
/**
11+
* @title Input
12+
* @description Input data for the actor run (Stringified JSON object). If you don't know what object to pass, use an empty object: {}
13+
*/
14+
input: string;
15+
16+
/**
17+
* @title Timeout (seconds)
18+
* @description Maximum timeout for the run in seconds
19+
*/
20+
timeout?: number;
21+
22+
/**
23+
* @title Memory (MB)
24+
* @description Amount of memory allocated for the run in megabytes
25+
*/
26+
memory?: number;
27+
28+
/**
29+
* @title Build
30+
* @description Specific build version to use (optional)
31+
*/
32+
build?: string;
33+
}
34+
35+
/**
36+
* @name RUN_ACTOR_V2
37+
* @title Run Actor V2
38+
* @description Run an Apify actor synchronously and return dataset items
39+
*/
40+
export default async function runActorV2(
41+
props: Props,
42+
_req: Request,
43+
ctx: AppContext,
44+
): Promise<
45+
{ data: Array<Record<string, unknown>>; error: null } | {
46+
error: string;
47+
data: null;
48+
}
49+
> {
50+
try {
51+
const { actorId, input: inputString, timeout, memory, build } = props;
52+
53+
if (!actorId) {
54+
return { error: "Actor ID is required", data: null };
55+
}
56+
57+
const response = await ctx.api
58+
["POST /v2/acts/:actorId/run-sync-get-dataset-items"]({
59+
actorId,
60+
timeout,
61+
memory,
62+
build,
63+
}, {
64+
body: JSON.parse(inputString),
65+
});
66+
67+
if (!response.ok) {
68+
const errorText = await response.text();
69+
throw new Error(`HTTP ${response.status}: ${errorText}`);
70+
}
71+
72+
const result = await response.json();
73+
return { data: result, error: null };
74+
} catch (error) {
75+
console.error("Error running actor:", error);
76+
return {
77+
error: ctx.errorHandler.toHttpError(error, "Error running actor"),
78+
data: null,
79+
};
80+
}
81+
}

apify/loaders/getActorRun.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AppContext } from "../mod.ts";
2-
import { ActorRun } from "../utils/types.ts";
2+
import { ActorRunResponse } from "../utils/types.ts";
33

44
export interface Props {
55
/**
@@ -13,6 +13,12 @@ export interface Props {
1313
* @description The ID of the actor run
1414
*/
1515
runId: string;
16+
17+
/**
18+
* @title Include Dataset Items
19+
* @description If true, include dataset items in the response
20+
*/
21+
includeDatasetItems?: boolean;
1622
}
1723

1824
/**
@@ -24,7 +30,7 @@ export default async function getActorRun(
2430
props: Props,
2531
_req: Request,
2632
ctx: AppContext,
27-
): Promise<ActorRun | { error: string }> {
33+
): Promise<ActorRunResponse | { error: string }> {
2834
try {
2935
const { actorId, runId } = props;
3036

@@ -37,7 +43,18 @@ export default async function getActorRun(
3743
runId,
3844
});
3945

40-
return response.json();
46+
const result = await response.json() as ActorRunResponse;
47+
48+
if (props.includeDatasetItems && result.data.defaultDatasetId) {
49+
const datasetItemsResponse = await ctx.api
50+
["GET /v2/datasets/:datasetId/items"]({
51+
datasetId: result.data.defaultDatasetId,
52+
format: "json",
53+
});
54+
result.data.results = await datasetItemsResponse.json(); // Place dataset items in the response.
55+
}
56+
57+
return result;
4158
} catch (error) {
4259
console.error("Error getting actor run:", error);
4360
return ctx.errorHandler.toHttpError(error, "Error getting actor run");

apify/manifest.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file is automatically updated during development when running `dev.ts`.
44

55
import * as $$$$$$$$$0 from "./actions/runActor.ts";
6+
import * as $$$$$$$$$1 from "./actions/runActorAsync.ts";
7+
import * as $$$$$$$$$2 from "./actions/runActorV2.ts";
68
import * as $$$0 from "./loaders/getActor.ts";
79
import * as $$$1 from "./loaders/getActorRun.ts";
810
import * as $$$2 from "./loaders/listActorRuns.ts";
@@ -17,6 +19,8 @@ const manifest = {
1719
},
1820
"actions": {
1921
"apify/actions/runActor.ts": $$$$$$$$$0,
22+
"apify/actions/runActorAsync.ts": $$$$$$$$$1,
23+
"apify/actions/runActorV2.ts": $$$$$$$$$2,
2024
},
2125
"name": "apify",
2226
"baseUrl": import.meta.url,

0 commit comments

Comments
 (0)