@unisian/shopify-admin 0.0.0 → 0.6.0
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/access-token-rejected.d.mts +10 -0
- package/dist/access-token-rejected.mjs +12 -0
- package/dist/admin-api.d.mts +45 -0
- package/dist/admin-api.mjs +103 -0
- package/dist/admin-bulk-query-registry.d.mts +26 -0
- package/dist/admin-bulk-query-registry.mjs +8 -0
- package/dist/admin-operation-registry.d.mts +11 -0
- package/dist/admin-operation-registry.mjs +8 -0
- package/dist/admin-query-failed.d.mts +11 -0
- package/dist/admin-query-failed.mjs +13 -0
- package/dist/bulk/bulk-operation-refused.d.mts +15 -0
- package/dist/bulk/bulk-operation-refused.mjs +18 -0
- package/dist/bulk/bulk-operations-finish.d.mts +13 -0
- package/dist/bulk/bulk-operations-finish.mjs +26 -0
- package/dist/bulk/bulk-result-failed.d.mts +10 -0
- package/dist/bulk/bulk-result-failed.mjs +12 -0
- package/dist/bulk/bulk-results.mjs +131 -0
- package/dist/bulk/bulk-transport.d.mts +33 -0
- package/dist/bulk/bulk-transport.mjs +118 -0
- package/dist/bulk/bulk-upload-failed.d.mts +11 -0
- package/dist/bulk/bulk-upload-failed.mjs +13 -0
- package/dist/bulk/read-only-shopify-bulk.d.mts +26 -0
- package/dist/bulk/read-only-shopify-bulk.mjs +23 -0
- package/dist/bulk/shopify-bulk.d.mts +47 -0
- package/dist/bulk/shopify-bulk.mjs +123 -0
- package/dist/bulk.d.mts +8 -0
- package/dist/bulk.mjs +7 -0
- package/dist/delegate-token-refused.d.mts +10 -0
- package/dist/delegate-token-refused.mjs +12 -0
- package/dist/delegate-token.d.mts +17 -0
- package/dist/delegate-token.mjs +45 -0
- package/dist/index.d.mts +12 -0
- package/dist/index.mjs +11 -0
- package/dist/mutation-refused.d.mts +10 -0
- package/dist/mutation-refused.mjs +12 -0
- package/dist/operations.d.mts +12 -0
- package/dist/operations.mjs +1 -0
- package/dist/read-only-admin.d.mts +49 -0
- package/dist/read-only-admin.mjs +60 -0
- package/dist/shopify-layer.d.mts +11 -0
- package/dist/shopify-layer.mjs +8 -0
- package/dist/testing.d.mts +29 -0
- package/dist/testing.mjs +52 -0
- package/package.json +35 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/bulk/bulk-upload-failed.d.ts
|
|
3
|
+
declare const BulkUploadFailed_base: Schema.Class<BulkUploadFailed, Schema.TaggedStruct<"BulkUploadFailed", {
|
|
4
|
+
readonly cause: Schema.Defect;
|
|
5
|
+
readonly operation: Schema.String;
|
|
6
|
+
readonly shop: Schema.String;
|
|
7
|
+
}>, import("effect/Cause").YieldableError>;
|
|
8
|
+
export declare class BulkUploadFailed extends BulkUploadFailed_base {
|
|
9
|
+
get message(): string;
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/bulk/bulk-upload-failed.ts
|
|
3
|
+
var BulkUploadFailed = class extends Schema.TaggedError()("BulkUploadFailed", {
|
|
4
|
+
cause: Schema.Defect(),
|
|
5
|
+
operation: Schema.String,
|
|
6
|
+
shop: Schema.String
|
|
7
|
+
}) {
|
|
8
|
+
get message() {
|
|
9
|
+
return `Staging the JSONL for bulk ${this.operation} failed for ${this.shop}`;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { BulkUploadFailed };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AdminBulkQueryRegistry } from "../admin-bulk-query-registry.mjs";
|
|
2
|
+
import { AdminBulkQueryDocument } from "../operations.mjs";
|
|
3
|
+
import { AdminCredential, AdminError } from "../admin-api.mjs";
|
|
4
|
+
import { BulkOperationRefused } from "./bulk-operation-refused.mjs";
|
|
5
|
+
import { BulkOperation, BulkQueryArgs, BulkReads } from "./bulk-transport.mjs";
|
|
6
|
+
import { MutationRefused } from "../mutation-refused.mjs";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import { ShopDomain } from "@unisian/shopify-sessions";
|
|
11
|
+
//#region src/bulk/read-only-shopify-bulk.d.ts
|
|
12
|
+
declare const ReadOnlyShopifyBulk_base: Context.ServiceClass<ReadOnlyShopifyBulk, "@unisian/shopify-admin/ReadOnlyShopifyBulk", BulkReads & {
|
|
13
|
+
readonly query: <const Q extends AdminBulkQueryDocument>(document: Q, ...args: BulkQueryArgs<Q>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused | MutationRefused>;
|
|
14
|
+
}>;
|
|
15
|
+
export declare class ReadOnlyShopifyBulk extends ReadOnlyShopifyBulk_base {
|
|
16
|
+
private static readonly over;
|
|
17
|
+
static readonly makeForShop: (shop: ShopDomain) => Effect.Effect<BulkReads & {
|
|
18
|
+
readonly query: <const Q extends AdminBulkQueryDocument>(document: Q, ...args: BulkQueryArgs<Q>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused | MutationRefused>;
|
|
19
|
+
}, never, AdminBulkQueryRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | import("@unisian/shopify-auth").ShopifyApp>;
|
|
20
|
+
static readonly layerForShop: (shop: ShopDomain) => Layer.Layer<ReadOnlyShopifyBulk, never, AdminBulkQueryRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | import("@unisian/shopify-auth").ShopifyApp>;
|
|
21
|
+
static readonly makeForToken: (credential: AdminCredential, apiVersion: string) => Effect.Effect<BulkReads & {
|
|
22
|
+
readonly query: <const Q extends AdminBulkQueryDocument>(document: Q, ...args: BulkQueryArgs<Q>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused | MutationRefused>;
|
|
23
|
+
}, never, AdminBulkQueryRegistry | import("effect/http/HttpClient").HttpClient>;
|
|
24
|
+
static readonly layerForToken: (credential: AdminCredential, apiVersion: string) => Layer.Layer<ReadOnlyShopifyBulk, never, AdminBulkQueryRegistry | import("effect/http/HttpClient").HttpClient>;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MutationRefused } from "../mutation-refused.mjs";
|
|
2
|
+
import { holdsMutation } from "../read-only-admin.mjs";
|
|
3
|
+
import { reads, submitQuery, transportForShop, transportForToken } from "./bulk-transport.mjs";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import * as Layer from "effect/Layer";
|
|
7
|
+
//#region src/bulk/read-only-shopify-bulk.ts
|
|
8
|
+
const refuseMutation = (shop) => (query) => holdsMutation(query.document.join("")) ? Effect.fail(new MutationRefused({
|
|
9
|
+
operation: "bulkOperationRunQuery",
|
|
10
|
+
shop
|
|
11
|
+
})) : Effect.succeed(query);
|
|
12
|
+
var ReadOnlyShopifyBulk = class ReadOnlyShopifyBulk extends Context.Service()("@unisian/shopify-admin/ReadOnlyShopifyBulk") {
|
|
13
|
+
static over = (transport) => ReadOnlyShopifyBulk.of({
|
|
14
|
+
...reads(transport),
|
|
15
|
+
query: submitQuery(transport, refuseMutation(transport.shop))
|
|
16
|
+
});
|
|
17
|
+
static makeForShop = (shop) => transportForShop(shop).pipe(Effect.map(ReadOnlyShopifyBulk.over));
|
|
18
|
+
static layerForShop = (shop) => Layer.effect(ReadOnlyShopifyBulk, ReadOnlyShopifyBulk.makeForShop(shop));
|
|
19
|
+
static makeForToken = (credential, apiVersion) => transportForToken(credential, apiVersion).pipe(Effect.map(ReadOnlyShopifyBulk.over));
|
|
20
|
+
static layerForToken = (credential, apiVersion) => Layer.effect(ReadOnlyShopifyBulk, ReadOnlyShopifyBulk.makeForToken(credential, apiVersion));
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ReadOnlyShopifyBulk };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { AdminBulkQueryRegistry } from "../admin-bulk-query-registry.mjs";
|
|
2
|
+
import { AdminOperationRegistry } from "../admin-operation-registry.mjs";
|
|
3
|
+
import { AdminBulkQueryDocument, AdminMutationDocument, AdminOperations } from "../operations.mjs";
|
|
4
|
+
import { AdminCredential, AdminError } from "../admin-api.mjs";
|
|
5
|
+
import { BulkOperationRefused } from "./bulk-operation-refused.mjs";
|
|
6
|
+
import { BulkResultFailed } from "./bulk-result-failed.mjs";
|
|
7
|
+
import { BulkOperation, BulkQueryArgs, BulkReads } from "./bulk-transport.mjs";
|
|
8
|
+
import { BulkUploadFailed } from "./bulk-upload-failed.mjs";
|
|
9
|
+
import * as Context from "effect/Context";
|
|
10
|
+
import * as Effect from "effect/Effect";
|
|
11
|
+
import * as Layer from "effect/Layer";
|
|
12
|
+
import * as Stream from "effect/Stream";
|
|
13
|
+
import { ShopDomain } from "@unisian/shopify-sessions";
|
|
14
|
+
//#region src/bulk/shopify-bulk.d.ts
|
|
15
|
+
export interface BulkResultLine<Data> {
|
|
16
|
+
readonly __lineNumber?: number;
|
|
17
|
+
readonly data?: Data | null;
|
|
18
|
+
readonly errors?: readonly {
|
|
19
|
+
readonly message: string;
|
|
20
|
+
}[];
|
|
21
|
+
}
|
|
22
|
+
declare const ShopifyBulk_base: Context.ServiceClass<ShopifyBulk, "@unisian/shopify-admin/ShopifyBulk", BulkReads & {
|
|
23
|
+
readonly query: <const Q extends AdminBulkQueryDocument>(document: Q, ...args: BulkQueryArgs<Q>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused>;
|
|
24
|
+
readonly mutation: <const M extends AdminMutationDocument>(document: M, variables: Iterable<AdminOperations[M]["variables"]>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused | BulkUploadFailed>;
|
|
25
|
+
readonly stage: <const M extends AdminMutationDocument>(document: M, variables: Iterable<AdminOperations[M]["variables"]>) => Effect.Effect<string, AdminError | BulkOperationRefused | BulkUploadFailed>;
|
|
26
|
+
readonly runMutation: (document: AdminMutationDocument, stagedUploadPath: string) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused>;
|
|
27
|
+
readonly results: <const M extends AdminMutationDocument>(document: M, url: string | null) => Stream.Stream<BulkResultLine<AdminOperations[M]["data"]>, BulkResultFailed>;
|
|
28
|
+
}>;
|
|
29
|
+
export declare class ShopifyBulk extends ShopifyBulk_base {
|
|
30
|
+
static readonly makeForShop: (shop: ShopDomain) => Effect.Effect<BulkReads & {
|
|
31
|
+
readonly query: <const Q extends AdminBulkQueryDocument>(document: Q, ...args: BulkQueryArgs<Q>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused>;
|
|
32
|
+
readonly mutation: <const M extends AdminMutationDocument>(document: M, variables: Iterable<AdminOperations[M]["variables"]>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused | BulkUploadFailed>;
|
|
33
|
+
readonly stage: <const M extends AdminMutationDocument>(document: M, variables: Iterable<AdminOperations[M]["variables"]>) => Effect.Effect<string, AdminError | BulkOperationRefused | BulkUploadFailed>;
|
|
34
|
+
readonly runMutation: (document: AdminMutationDocument, stagedUploadPath: string) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused>;
|
|
35
|
+
readonly results: <const M extends AdminMutationDocument>(document: M, url: string | null) => Stream.Stream<BulkResultLine<AdminOperations[M]["data"]>, BulkResultFailed>;
|
|
36
|
+
}, never, AdminBulkQueryRegistry | AdminOperationRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | import("@unisian/shopify-auth").ShopifyApp>;
|
|
37
|
+
static readonly layerForShop: (shop: ShopDomain) => Layer.Layer<ShopifyBulk, never, AdminBulkQueryRegistry | AdminOperationRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | import("@unisian/shopify-auth").ShopifyApp>;
|
|
38
|
+
static readonly makeForToken: (credential: AdminCredential, apiVersion: string) => Effect.Effect<BulkReads & {
|
|
39
|
+
readonly query: <const Q extends AdminBulkQueryDocument>(document: Q, ...args: BulkQueryArgs<Q>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused>;
|
|
40
|
+
readonly mutation: <const M extends AdminMutationDocument>(document: M, variables: Iterable<AdminOperations[M]["variables"]>) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused | BulkUploadFailed>;
|
|
41
|
+
readonly stage: <const M extends AdminMutationDocument>(document: M, variables: Iterable<AdminOperations[M]["variables"]>) => Effect.Effect<string, AdminError | BulkOperationRefused | BulkUploadFailed>;
|
|
42
|
+
readonly runMutation: (document: AdminMutationDocument, stagedUploadPath: string) => Effect.Effect<BulkOperation, AdminError | BulkOperationRefused>;
|
|
43
|
+
readonly results: <const M extends AdminMutationDocument>(document: M, url: string | null) => Stream.Stream<BulkResultLine<AdminOperations[M]["data"]>, BulkResultFailed>;
|
|
44
|
+
}, never, AdminBulkQueryRegistry | AdminOperationRegistry | import("effect/http/HttpClient").HttpClient>;
|
|
45
|
+
static readonly layerForToken: (credential: AdminCredential, apiVersion: string) => Layer.Layer<ShopifyBulk, never, AdminBulkQueryRegistry | AdminOperationRegistry | import("effect/http/HttpClient").HttpClient>;
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { AdminOperationRegistry } from "../admin-operation-registry.mjs";
|
|
2
|
+
import { BulkOperationRefused } from "./bulk-operation-refused.mjs";
|
|
3
|
+
import { bulkResults, resultText } from "./bulk-results.mjs";
|
|
4
|
+
import { Submitted, bulkOperationFields, reads, submitQuery, submitted, transportForShop, transportForToken } from "./bulk-transport.mjs";
|
|
5
|
+
import { BulkUploadFailed } from "./bulk-upload-failed.mjs";
|
|
6
|
+
import * as Schema from "effect/Schema";
|
|
7
|
+
import * as Context from "effect/Context";
|
|
8
|
+
import * as Effect from "effect/Effect";
|
|
9
|
+
import * as Layer from "effect/Layer";
|
|
10
|
+
import { HttpClientRequest, HttpClientResponse } from "effect/http";
|
|
11
|
+
import { withoutRequest } from "@unisian/shopify-auth";
|
|
12
|
+
import { operationFor } from "@unisian/shopify-auth/kernel";
|
|
13
|
+
import * as Stream from "effect/Stream";
|
|
14
|
+
//#region src/bulk/shopify-bulk.ts
|
|
15
|
+
const RunMutation = {
|
|
16
|
+
data: Schema.Struct({ bulkOperationRunMutation: Submitted }),
|
|
17
|
+
document: `mutation UnisianBulkRunMutation($mutation: String!, $stagedUploadPath: String!) { bulkOperationRunMutation(mutation: $mutation, stagedUploadPath: $stagedUploadPath) { bulkOperation { ${bulkOperationFields} } userErrors { code field message } } }`,
|
|
18
|
+
kind: "mutation",
|
|
19
|
+
name: "UnisianBulkRunMutation",
|
|
20
|
+
variables: Schema.Struct({
|
|
21
|
+
mutation: Schema.String,
|
|
22
|
+
stagedUploadPath: Schema.String
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
const StagedUpload = {
|
|
26
|
+
data: Schema.Struct({ stagedUploadsCreate: Schema.NullOr(Schema.Struct({
|
|
27
|
+
stagedTargets: Schema.NullOr(Schema.Array(Schema.Struct({
|
|
28
|
+
parameters: Schema.Array(Schema.Struct({
|
|
29
|
+
name: Schema.String,
|
|
30
|
+
value: Schema.String
|
|
31
|
+
})),
|
|
32
|
+
url: Schema.NullOr(Schema.String)
|
|
33
|
+
}))),
|
|
34
|
+
userErrors: Schema.Array(Schema.Struct({
|
|
35
|
+
field: Schema.NullOr(Schema.Array(Schema.String)),
|
|
36
|
+
message: Schema.String
|
|
37
|
+
}))
|
|
38
|
+
})) }),
|
|
39
|
+
document: "mutation UnisianBulkStagedUpload($filename: String!) { stagedUploadsCreate(input: [{ resource: BULK_MUTATION_VARIABLES, filename: $filename, mimeType: \"text/jsonl\", httpMethod: POST }]) { stagedTargets { url parameters { name value } } userErrors { field message } } }",
|
|
40
|
+
kind: "mutation",
|
|
41
|
+
name: "UnisianBulkStagedUpload",
|
|
42
|
+
variables: Schema.Struct({ filename: Schema.String })
|
|
43
|
+
};
|
|
44
|
+
const jsonlLimitBytes = 1e8;
|
|
45
|
+
const upload = ({ send, shop, client }, operation, jsonl) => Effect.gen(function* uploadGen() {
|
|
46
|
+
const uploadFailed = (cause) => new BulkUploadFailed({
|
|
47
|
+
cause: withoutRequest(cause),
|
|
48
|
+
operation,
|
|
49
|
+
shop
|
|
50
|
+
});
|
|
51
|
+
const filename = `${operation}.jsonl`;
|
|
52
|
+
const { stagedUploadsCreate } = yield* send(StagedUpload, { filename });
|
|
53
|
+
const userErrors = stagedUploadsCreate?.userErrors ?? [];
|
|
54
|
+
if (userErrors.length > 0) return yield* new BulkOperationRefused({
|
|
55
|
+
operation: "stagedUploadsCreate",
|
|
56
|
+
shop,
|
|
57
|
+
userErrors: userErrors.map((error) => ({
|
|
58
|
+
...error,
|
|
59
|
+
code: null
|
|
60
|
+
}))
|
|
61
|
+
});
|
|
62
|
+
const target = stagedUploadsCreate?.stagedTargets?.[0];
|
|
63
|
+
const url = target?.url ?? null;
|
|
64
|
+
const key = target?.parameters.find((parameter) => parameter.name === "key")?.value;
|
|
65
|
+
if (target === void 0 || url === null || key === void 0) return yield* uploadFailed("stagedUploadsCreate returned no target with a key");
|
|
66
|
+
const form = new FormData();
|
|
67
|
+
for (const parameter of target.parameters) form.append(parameter.name, parameter.value);
|
|
68
|
+
form.append("file", new Blob([jsonl], { type: "text/jsonl" }), filename);
|
|
69
|
+
yield* client.execute(HttpClientRequest.post(url).pipe(HttpClientRequest.bodyFormData(form))).pipe(Effect.flatMap(HttpClientResponse.filterStatusOk), Effect.mapError(uploadFailed));
|
|
70
|
+
return key;
|
|
71
|
+
});
|
|
72
|
+
const fullBulk = (transport, registry) => {
|
|
73
|
+
const { send, shop, client } = transport;
|
|
74
|
+
const mutationFor = (document) => operationFor(registry, document).pipe(Effect.filterOrElse((operation) => operation.kind === "mutation", (operation) => Effect.die(`${operation.name} is a query; a bulk mutation runs a mutation`)));
|
|
75
|
+
const stage = Effect.fn("ShopifyBulk.stage")(function* stageGen(document, variables) {
|
|
76
|
+
const operation = yield* mutationFor(document);
|
|
77
|
+
yield* Effect.annotateCurrentSpan("operation", operation.name);
|
|
78
|
+
const uploadFailed = (cause) => new BulkUploadFailed({
|
|
79
|
+
cause: withoutRequest(cause),
|
|
80
|
+
operation: operation.name,
|
|
81
|
+
shop
|
|
82
|
+
});
|
|
83
|
+
const lines = yield* Effect.forEach(variables, (line) => Schema.encodeUnknownEffect(operation.variables)(line).pipe(Effect.map((encoded) => `${JSON.stringify(encoded)}\n`), Effect.mapError(uploadFailed)));
|
|
84
|
+
const jsonl = new TextEncoder().encode(lines.join(""));
|
|
85
|
+
if (jsonl.byteLength > jsonlLimitBytes) return yield* uploadFailed(`the JSONL is ${jsonl.byteLength} bytes; Shopify takes ${jsonlLimitBytes} at most`);
|
|
86
|
+
return yield* upload(transport, operation.name, jsonl);
|
|
87
|
+
});
|
|
88
|
+
const runMutation = Effect.fn("ShopifyBulk.runMutation")(function* runMutationGen(document, stagedUploadPath) {
|
|
89
|
+
const operation = yield* mutationFor(document);
|
|
90
|
+
yield* Effect.annotateCurrentSpan("operation", operation.name);
|
|
91
|
+
const { bulkOperationRunMutation } = yield* send(RunMutation, {
|
|
92
|
+
mutation: operation.document,
|
|
93
|
+
stagedUploadPath
|
|
94
|
+
});
|
|
95
|
+
return yield* submitted("bulkOperationRunMutation", shop)(bulkOperationRunMutation);
|
|
96
|
+
});
|
|
97
|
+
const mutation = (document, variables) => stage(document, variables).pipe(Effect.flatMap((stagedUploadPath) => runMutation(document, stagedUploadPath)), Effect.withSpan("ShopifyBulk.mutation"));
|
|
98
|
+
const results = (document, url) => {
|
|
99
|
+
return mutationFor(document).pipe(Effect.map((operation) => resultText(client, url).pipe(bulkResults(operation.name, operation.data))), Stream.unwrap);
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
...reads(transport),
|
|
103
|
+
mutation,
|
|
104
|
+
query: submitQuery(transport, Effect.succeed),
|
|
105
|
+
results,
|
|
106
|
+
runMutation,
|
|
107
|
+
stage
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
var ShopifyBulk = class ShopifyBulk extends Context.Service()("@unisian/shopify-admin/ShopifyBulk") {
|
|
111
|
+
static makeForShop = (shop) => Effect.gen(function* makeForShop() {
|
|
112
|
+
const registry = yield* AdminOperationRegistry;
|
|
113
|
+
return ShopifyBulk.of(fullBulk(yield* transportForShop(shop), registry));
|
|
114
|
+
});
|
|
115
|
+
static layerForShop = (shop) => Layer.effect(ShopifyBulk, ShopifyBulk.makeForShop(shop));
|
|
116
|
+
static makeForToken = (credential, apiVersion) => Effect.gen(function* makeForToken() {
|
|
117
|
+
const registry = yield* AdminOperationRegistry;
|
|
118
|
+
return ShopifyBulk.of(fullBulk(yield* transportForToken(credential, apiVersion), registry));
|
|
119
|
+
});
|
|
120
|
+
static layerForToken = (credential, apiVersion) => Layer.effect(ShopifyBulk, ShopifyBulk.makeForToken(credential, apiVersion));
|
|
121
|
+
};
|
|
122
|
+
//#endregion
|
|
123
|
+
export { ShopifyBulk };
|
package/dist/bulk.d.mts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BulkOperationRefused } from "./bulk/bulk-operation-refused.mjs";
|
|
2
|
+
import { BulkResultFailed } from "./bulk/bulk-result-failed.mjs";
|
|
3
|
+
import { BulkOperation, BulkQueryArgs, BulkQueryOptions } from "./bulk/bulk-transport.mjs";
|
|
4
|
+
import { BulkUploadFailed } from "./bulk/bulk-upload-failed.mjs";
|
|
5
|
+
import { BulkResultLine, ShopifyBulk } from "./bulk/shopify-bulk.mjs";
|
|
6
|
+
import { ReadOnlyShopifyBulk } from "./bulk/read-only-shopify-bulk.mjs";
|
|
7
|
+
import { BULK_OPERATIONS_FINISH_TOPIC, BulkOperationsFinish } from "./bulk/bulk-operations-finish.mjs";
|
|
8
|
+
export { BULK_OPERATIONS_FINISH_TOPIC, type BulkOperation, BulkOperationRefused, BulkOperationsFinish, type BulkQueryArgs, type BulkQueryOptions, BulkResultFailed, type BulkResultLine, BulkUploadFailed, ReadOnlyShopifyBulk, ShopifyBulk };
|
package/dist/bulk.mjs
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BulkOperationRefused } from "./bulk/bulk-operation-refused.mjs";
|
|
2
|
+
import { BulkResultFailed } from "./bulk/bulk-result-failed.mjs";
|
|
3
|
+
import { BulkUploadFailed } from "./bulk/bulk-upload-failed.mjs";
|
|
4
|
+
import { ShopifyBulk } from "./bulk/shopify-bulk.mjs";
|
|
5
|
+
import { ReadOnlyShopifyBulk } from "./bulk/read-only-shopify-bulk.mjs";
|
|
6
|
+
import { BULK_OPERATIONS_FINISH_TOPIC, BulkOperationsFinish } from "./bulk/bulk-operations-finish.mjs";
|
|
7
|
+
export { BULK_OPERATIONS_FINISH_TOPIC, BulkOperationRefused, BulkOperationsFinish, BulkResultFailed, BulkUploadFailed, ReadOnlyShopifyBulk, ShopifyBulk };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/delegate-token-refused.d.ts
|
|
3
|
+
declare const DelegateTokenRefused_base: Schema.Class<DelegateTokenRefused, Schema.TaggedStruct<"DelegateTokenRefused", {
|
|
4
|
+
readonly codes: Schema.$Array<Schema.NullOr<Schema.String>>;
|
|
5
|
+
readonly shop: Schema.String;
|
|
6
|
+
}>, import("effect/Cause").YieldableError>;
|
|
7
|
+
export declare class DelegateTokenRefused extends DelegateTokenRefused_base {
|
|
8
|
+
get message(): string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/delegate-token-refused.ts
|
|
3
|
+
var DelegateTokenRefused = class extends Schema.TaggedError()("DelegateTokenRefused", {
|
|
4
|
+
codes: Schema.Array(Schema.NullOr(Schema.String)),
|
|
5
|
+
shop: Schema.String
|
|
6
|
+
}) {
|
|
7
|
+
get message() {
|
|
8
|
+
return `Shopify refused a delegate token for ${this.shop} (${this.codes.join(", ")})`;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DelegateTokenRefused };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AccessTokenRejected } from "./access-token-rejected.mjs";
|
|
2
|
+
import { AdminQueryFailed } from "./admin-query-failed.mjs";
|
|
3
|
+
import { AdminCredential } from "./admin-api.mjs";
|
|
4
|
+
import { DelegateTokenRefused } from "./delegate-token-refused.mjs";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
//#region src/delegate-token.d.ts
|
|
8
|
+
declare const DelegateToken_base: Schema.Class<DelegateToken, Schema.Struct<{
|
|
9
|
+
readonly accessToken: Schema.Redacted<Schema.String>;
|
|
10
|
+
readonly expiresAt: Schema.Int;
|
|
11
|
+
}>, {}>;
|
|
12
|
+
export declare class DelegateToken extends DelegateToken_base {}
|
|
13
|
+
export declare const createDelegateToken: (apiVersion: string, parent: AdminCredential, delegate: {
|
|
14
|
+
readonly scopes: readonly string[];
|
|
15
|
+
readonly expiresInSeconds: number;
|
|
16
|
+
}) => Effect.Effect<DelegateToken, AccessTokenRejected | AdminQueryFailed | DelegateTokenRefused, import("effect/http/HttpClient").HttpClient>;
|
|
17
|
+
//#endregion
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { sendAdminDocument } from "./admin-api.mjs";
|
|
2
|
+
import { DelegateTokenRefused } from "./delegate-token-refused.mjs";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as Effect from "effect/Effect";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
import * as Clock from "effect/Clock";
|
|
7
|
+
//#region src/delegate-token.ts
|
|
8
|
+
const createDelegate = `mutation DelegateAccessTokenCreate($input: DelegateAccessTokenInput!) {
|
|
9
|
+
delegateAccessTokenCreate(input: $input) {
|
|
10
|
+
delegateAccessToken { accessToken expiresIn }
|
|
11
|
+
userErrors { code message }
|
|
12
|
+
}
|
|
13
|
+
}`;
|
|
14
|
+
const Created = Schema.Struct({ delegateAccessTokenCreate: Schema.Struct({
|
|
15
|
+
delegateAccessToken: Schema.NullOr(Schema.Struct({
|
|
16
|
+
accessToken: Schema.String,
|
|
17
|
+
expiresIn: Schema.Int
|
|
18
|
+
})),
|
|
19
|
+
userErrors: Schema.Array(Schema.Struct({
|
|
20
|
+
code: Schema.NullOr(Schema.String),
|
|
21
|
+
message: Schema.String
|
|
22
|
+
}))
|
|
23
|
+
}) });
|
|
24
|
+
var DelegateToken = class extends Schema.Class("DelegateToken")({
|
|
25
|
+
accessToken: Schema.Redacted(Schema.String),
|
|
26
|
+
expiresAt: Schema.Int
|
|
27
|
+
}) {};
|
|
28
|
+
const createDelegateToken = Effect.fn("createDelegateToken")(function* createDelegateToken(apiVersion, parent, delegate) {
|
|
29
|
+
const result = yield* sendAdminDocument(apiVersion, parent, createDelegate, { input: {
|
|
30
|
+
delegateAccessScope: [...delegate.scopes],
|
|
31
|
+
expiresIn: delegate.expiresInSeconds
|
|
32
|
+
} });
|
|
33
|
+
const { delegateAccessTokenCreate: created } = yield* Schema.decodeUnknownEffect(Created)(result.data).pipe(Effect.orDie);
|
|
34
|
+
if (created.delegateAccessToken === null) return yield* new DelegateTokenRefused({
|
|
35
|
+
codes: created.userErrors.map((error) => error.code),
|
|
36
|
+
shop: parent.shop
|
|
37
|
+
});
|
|
38
|
+
const now = yield* Clock.currentTimeMillis;
|
|
39
|
+
return new DelegateToken({
|
|
40
|
+
accessToken: Redacted.make(created.delegateAccessToken.accessToken),
|
|
41
|
+
expiresAt: now + created.delegateAccessToken.expiresIn * 1e3
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
//#endregion
|
|
45
|
+
export { DelegateToken, createDelegateToken };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AdminBulkQuery, AdminBulkQueryRegistry, BulkConnection, BulkLines } from "./admin-bulk-query-registry.mjs";
|
|
2
|
+
import { AccessTokenRejected } from "./access-token-rejected.mjs";
|
|
3
|
+
import { AdminOperation, AdminOperationRegistry } from "./admin-operation-registry.mjs";
|
|
4
|
+
import { AdminQueryFailed } from "./admin-query-failed.mjs";
|
|
5
|
+
import { AdminBulkQueries, AdminBulkQueryDocument, AdminDocument, AdminMutationDocument, AdminOperations, AdminQueryDocument } from "./operations.mjs";
|
|
6
|
+
import { AdminCredential, AdminDocumentResult, AdminError, ShopifyAdmin, sendAdminDocument } from "./admin-api.mjs";
|
|
7
|
+
import { MutationRefused } from "./mutation-refused.mjs";
|
|
8
|
+
import { DelegateTokenRefused } from "./delegate-token-refused.mjs";
|
|
9
|
+
import { DelegateToken, createDelegateToken } from "./delegate-token.mjs";
|
|
10
|
+
import { BulkOperationRunQueryData, ReadOnlyShopifyAdmin } from "./read-only-admin.mjs";
|
|
11
|
+
import { ShopifyLayerConfig, shopifyLayer } from "./shopify-layer.mjs";
|
|
12
|
+
export { AccessTokenRejected, type AdminBulkQueries, type AdminBulkQuery, type AdminBulkQueryDocument, AdminBulkQueryRegistry, type AdminCredential, type AdminDocument, type AdminDocumentResult, type AdminError, type AdminMutationDocument, type AdminOperation, AdminOperationRegistry, type AdminOperations, type AdminQueryDocument, AdminQueryFailed, type BulkConnection, type BulkLines, type BulkOperationRunQueryData, DelegateToken, DelegateTokenRefused, MutationRefused, ReadOnlyShopifyAdmin, ShopifyAdmin, type ShopifyLayerConfig, createDelegateToken, sendAdminDocument, shopifyLayer };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AccessTokenRejected } from "./access-token-rejected.mjs";
|
|
2
|
+
import { AdminOperationRegistry } from "./admin-operation-registry.mjs";
|
|
3
|
+
import { AdminQueryFailed } from "./admin-query-failed.mjs";
|
|
4
|
+
import { ShopifyAdmin, sendAdminDocument } from "./admin-api.mjs";
|
|
5
|
+
import { AdminBulkQueryRegistry } from "./admin-bulk-query-registry.mjs";
|
|
6
|
+
import { DelegateTokenRefused } from "./delegate-token-refused.mjs";
|
|
7
|
+
import { DelegateToken, createDelegateToken } from "./delegate-token.mjs";
|
|
8
|
+
import { MutationRefused } from "./mutation-refused.mjs";
|
|
9
|
+
import { ReadOnlyShopifyAdmin } from "./read-only-admin.mjs";
|
|
10
|
+
import { shopifyLayer } from "./shopify-layer.mjs";
|
|
11
|
+
export { AccessTokenRejected, AdminBulkQueryRegistry, AdminOperationRegistry, AdminQueryFailed, DelegateToken, DelegateTokenRefused, MutationRefused, ReadOnlyShopifyAdmin, ShopifyAdmin, createDelegateToken, sendAdminDocument, shopifyLayer };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/mutation-refused.d.ts
|
|
3
|
+
declare const MutationRefused_base: Schema.Class<MutationRefused, Schema.TaggedStruct<"MutationRefused", {
|
|
4
|
+
readonly operation: Schema.String;
|
|
5
|
+
readonly shop: Schema.String;
|
|
6
|
+
}>, import("effect/Cause").YieldableError>;
|
|
7
|
+
export declare class MutationRefused extends MutationRefused_base {
|
|
8
|
+
get message(): string;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
//#region src/mutation-refused.ts
|
|
3
|
+
var MutationRefused = class extends Schema.TaggedError()("MutationRefused", {
|
|
4
|
+
operation: Schema.String,
|
|
5
|
+
shop: Schema.String
|
|
6
|
+
}) {
|
|
7
|
+
get message() {
|
|
8
|
+
return `The read-only Admin client refused ${this.operation} for ${this.shop}: it sends queries only`;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MutationRefused };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/operations.d.ts
|
|
2
|
+
export interface AdminOperations {}
|
|
3
|
+
export type AdminDocument = Extract<keyof AdminOperations, string>;
|
|
4
|
+
export type AdminQueryDocument = { readonly [Q in AdminDocument]: AdminOperations[Q] extends {
|
|
5
|
+
readonly kind: "query";
|
|
6
|
+
} ? Q : never; }[AdminDocument];
|
|
7
|
+
export type AdminMutationDocument = { readonly [Q in AdminDocument]: AdminOperations[Q] extends {
|
|
8
|
+
readonly kind: "mutation";
|
|
9
|
+
} ? Q : never; }[AdminDocument];
|
|
10
|
+
export interface AdminBulkQueries {}
|
|
11
|
+
export type AdminBulkQueryDocument = Extract<keyof AdminBulkQueries, string>;
|
|
12
|
+
//#endregion
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AdminOperationRegistry } from "./admin-operation-registry.mjs";
|
|
2
|
+
import { AdminOperations, AdminQueryDocument } from "./operations.mjs";
|
|
3
|
+
import { AdminCredential, AdminError, VariablesArgs } from "./admin-api.mjs";
|
|
4
|
+
import { MutationRefused } from "./mutation-refused.mjs";
|
|
5
|
+
import * as Schema from "effect/Schema";
|
|
6
|
+
import * as Context from "effect/Context";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import { ShopDomain } from "@unisian/shopify-sessions";
|
|
10
|
+
//#region src/read-only-admin.d.ts
|
|
11
|
+
declare const BulkOperationRunQuery: {
|
|
12
|
+
data: Schema.Struct<{
|
|
13
|
+
readonly bulkOperationRunQuery: Schema.NullOr<Schema.Struct<{
|
|
14
|
+
readonly bulkOperation: Schema.NullOr<Schema.Struct<{
|
|
15
|
+
readonly id: Schema.String;
|
|
16
|
+
readonly status: Schema.String;
|
|
17
|
+
}>>;
|
|
18
|
+
readonly userErrors: Schema.$Array<Schema.Struct<{
|
|
19
|
+
readonly field: Schema.NullOr<Schema.$Array<Schema.String>>;
|
|
20
|
+
readonly message: Schema.String;
|
|
21
|
+
}>>;
|
|
22
|
+
}>>;
|
|
23
|
+
}>;
|
|
24
|
+
document: string;
|
|
25
|
+
kind: "mutation";
|
|
26
|
+
name: string;
|
|
27
|
+
variables: Schema.Struct<{
|
|
28
|
+
readonly query: Schema.String;
|
|
29
|
+
}>;
|
|
30
|
+
};
|
|
31
|
+
export type BulkOperationRunQueryData = typeof BulkOperationRunQuery.data.Type;
|
|
32
|
+
declare const ReadOnlyShopifyAdmin_base: Context.ServiceClass<ReadOnlyShopifyAdmin, "@unisian/shopify-admin/ReadOnlyShopifyAdmin", {
|
|
33
|
+
readonly graphql: <const Q extends AdminQueryDocument>(document: Q, ...variables: VariablesArgs<Q>) => Effect.Effect<AdminOperations[Q]["data"], AdminError>;
|
|
34
|
+
readonly bulkOperationRunQuery: (query: string) => Effect.Effect<BulkOperationRunQueryData, AdminError | MutationRefused>;
|
|
35
|
+
}>;
|
|
36
|
+
export declare class ReadOnlyShopifyAdmin extends ReadOnlyShopifyAdmin_base {
|
|
37
|
+
private static readonly over;
|
|
38
|
+
static readonly makeForShop: (shop: ShopDomain) => Effect.Effect<{
|
|
39
|
+
readonly graphql: <const Q extends AdminQueryDocument>(document: Q, ...variables: VariablesArgs<Q>) => Effect.Effect<AdminOperations[Q]["data"], AdminError>;
|
|
40
|
+
readonly bulkOperationRunQuery: (query: string) => Effect.Effect<BulkOperationRunQueryData, AdminError | MutationRefused>;
|
|
41
|
+
}, never, AdminOperationRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | import("@unisian/shopify-auth").ShopifyApp>;
|
|
42
|
+
static readonly layerForShop: (shop: ShopDomain) => Layer.Layer<ReadOnlyShopifyAdmin, never, AdminOperationRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | import("@unisian/shopify-auth").ShopifyApp>;
|
|
43
|
+
static readonly makeForToken: (credential: AdminCredential, apiVersion: string) => Effect.Effect<{
|
|
44
|
+
readonly graphql: <const Q extends AdminQueryDocument>(document: Q, ...variables: VariablesArgs<Q>) => Effect.Effect<AdminOperations[Q]["data"], AdminError>;
|
|
45
|
+
readonly bulkOperationRunQuery: (query: string) => Effect.Effect<BulkOperationRunQueryData, AdminError | MutationRefused>;
|
|
46
|
+
}, never, AdminOperationRegistry | import("effect/http/HttpClient").HttpClient>;
|
|
47
|
+
static readonly layerForToken: (credential: AdminCredential, apiVersion: string) => Layer.Layer<ReadOnlyShopifyAdmin, never, AdminOperationRegistry | import("effect/http/HttpClient").HttpClient>;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AdminOperationRegistry } from "./admin-operation-registry.mjs";
|
|
2
|
+
import { sendForShop, sendForToken } from "./admin-api.mjs";
|
|
3
|
+
import { MutationRefused } from "./mutation-refused.mjs";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Effect from "effect/Effect";
|
|
7
|
+
import * as Layer from "effect/Layer";
|
|
8
|
+
import { operationFor } from "@unisian/shopify-auth/kernel";
|
|
9
|
+
//#region src/read-only-admin.ts
|
|
10
|
+
const BulkOperationRunQuery = {
|
|
11
|
+
data: Schema.Struct({ bulkOperationRunQuery: Schema.NullOr(Schema.Struct({
|
|
12
|
+
bulkOperation: Schema.NullOr(Schema.Struct({
|
|
13
|
+
id: Schema.String,
|
|
14
|
+
status: Schema.String
|
|
15
|
+
})),
|
|
16
|
+
userErrors: Schema.Array(Schema.Struct({
|
|
17
|
+
field: Schema.NullOr(Schema.Array(Schema.String)),
|
|
18
|
+
message: Schema.String
|
|
19
|
+
}))
|
|
20
|
+
})) }),
|
|
21
|
+
document: "mutation BulkOperationRunQuery($query: String!) {\n bulkOperationRunQuery(query: $query) {\n bulkOperation {\n id\n status\n }\n userErrors {\n field\n message\n }\n }\n}",
|
|
22
|
+
kind: "mutation",
|
|
23
|
+
name: "BulkOperationRunQuery",
|
|
24
|
+
variables: Schema.Struct({ query: Schema.String })
|
|
25
|
+
};
|
|
26
|
+
const graphqlComment = /#[^\n]*/gu;
|
|
27
|
+
const mutationKeyword = /(?:^|[\s{])mutation(?=[\s({#])/u;
|
|
28
|
+
const holdsMutation = (document) => mutationKeyword.test(document.replaceAll(graphqlComment, ""));
|
|
29
|
+
var ReadOnlyShopifyAdmin = class ReadOnlyShopifyAdmin extends Context.Service()("@unisian/shopify-admin/ReadOnlyShopifyAdmin") {
|
|
30
|
+
static over = (registry, send, shop) => {
|
|
31
|
+
const graphql = (document, ...[variables]) => {
|
|
32
|
+
return operationFor(registry, document).pipe(Effect.flatMap((operation) => operation.kind === "query" ? send(operation, variables ?? {}) : Effect.die(new MutationRefused({
|
|
33
|
+
operation: operation.name,
|
|
34
|
+
shop
|
|
35
|
+
}))));
|
|
36
|
+
};
|
|
37
|
+
const bulkOperationRunQuery = (query) => holdsMutation(query) ? Effect.fail(new MutationRefused({
|
|
38
|
+
operation: BulkOperationRunQuery.name,
|
|
39
|
+
shop
|
|
40
|
+
})) : send(BulkOperationRunQuery, { query });
|
|
41
|
+
return ReadOnlyShopifyAdmin.of({
|
|
42
|
+
bulkOperationRunQuery,
|
|
43
|
+
graphql
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
static makeForShop = (shop) => Effect.gen(function* makeForShop() {
|
|
47
|
+
const registry = yield* AdminOperationRegistry;
|
|
48
|
+
const send = yield* sendForShop(shop);
|
|
49
|
+
return ReadOnlyShopifyAdmin.over(registry, send, shop);
|
|
50
|
+
});
|
|
51
|
+
static layerForShop = (shop) => Layer.effect(ReadOnlyShopifyAdmin, ReadOnlyShopifyAdmin.makeForShop(shop));
|
|
52
|
+
static makeForToken = (credential, apiVersion) => Effect.gen(function* makeForToken() {
|
|
53
|
+
const registry = yield* AdminOperationRegistry;
|
|
54
|
+
const send = yield* sendForToken(credential, apiVersion);
|
|
55
|
+
return ReadOnlyShopifyAdmin.over(registry, send, credential.shop);
|
|
56
|
+
});
|
|
57
|
+
static layerForToken = (credential, apiVersion) => Layer.effect(ReadOnlyShopifyAdmin, ReadOnlyShopifyAdmin.makeForToken(credential, apiVersion));
|
|
58
|
+
};
|
|
59
|
+
//#endregion
|
|
60
|
+
export { ReadOnlyShopifyAdmin, holdsMutation };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AdminOperation, AdminOperationRegistry } from "./admin-operation-registry.mjs";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import { ShopSessionsNamespace, ShopifyApp, ShopifyAppConfig, ShopifyAuth } from "@unisian/shopify-auth";
|
|
4
|
+
//#region src/shopify-layer.d.ts
|
|
5
|
+
export interface ShopifyLayerConfig {
|
|
6
|
+
readonly app: ShopifyAppConfig;
|
|
7
|
+
readonly sessions: ShopSessionsNamespace;
|
|
8
|
+
readonly operations: Readonly<Record<string, AdminOperation>>;
|
|
9
|
+
}
|
|
10
|
+
export declare const shopifyLayer: (config: ShopifyLayerConfig) => Layer.Layer<AdminOperationRegistry | import("effect/http/HttpClient").HttpClient | import("@unisian/shopify-auth").SessionOwner | ShopifyApp | ShopifyAuth, never, never>;
|
|
11
|
+
//#endregion
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AdminOperationRegistry } from "./admin-operation-registry.mjs";
|
|
2
|
+
import * as Layer from "effect/Layer";
|
|
3
|
+
import { FetchHttpClient } from "effect/http";
|
|
4
|
+
import { ShopifyApp, ShopifyAuth, shopSessionsLayer } from "@unisian/shopify-auth";
|
|
5
|
+
//#region src/shopify-layer.ts
|
|
6
|
+
const shopifyLayer = (config) => ShopifyAuth.layer.pipe(Layer.provideMerge(Layer.mergeAll(ShopifyApp.layer(config.app), shopSessionsLayer(config.sessions), AdminOperationRegistry.layer(config.operations), FetchHttpClient.layer)));
|
|
7
|
+
//#endregion
|
|
8
|
+
export { shopifyLayer };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AdminBulkQuery } from "./admin-bulk-query-registry.mjs";
|
|
2
|
+
import { AdminOperation } from "./admin-operation-registry.mjs";
|
|
3
|
+
import { ShopifyAdmin } from "./admin-api.mjs";
|
|
4
|
+
import { ShopifyBulk } from "./bulk/shopify-bulk.mjs";
|
|
5
|
+
import { ReadOnlyShopifyBulk } from "./bulk/read-only-shopify-bulk.mjs";
|
|
6
|
+
import { ReadOnlyShopifyAdmin } from "./read-only-admin.mjs";
|
|
7
|
+
import * as Schema from "effect/Schema";
|
|
8
|
+
import * as Layer from "effect/Layer";
|
|
9
|
+
import { ShopDomain } from "@unisian/shopify-sessions";
|
|
10
|
+
//#region src/testing.d.ts
|
|
11
|
+
export interface SentOperation {
|
|
12
|
+
readonly shop: string;
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly variables: Schema.Json | undefined;
|
|
15
|
+
}
|
|
16
|
+
export type Answer = (variables: Schema.Json | undefined) => Schema.Json;
|
|
17
|
+
export type FileAnswer = (request: Request) => Response | Promise<Response>;
|
|
18
|
+
export interface BulkStub {
|
|
19
|
+
readonly bulkQueries?: Readonly<Record<string, AdminBulkQuery>>;
|
|
20
|
+
readonly files?: Readonly<Record<string, FileAnswer>>;
|
|
21
|
+
}
|
|
22
|
+
export declare const adminStub: (shop: ShopDomain, operations: Readonly<Record<string, AdminOperation>>, answers: Readonly<Record<string, Answer>>, bulk?: BulkStub) => {
|
|
23
|
+
bulkLayer: Layer.Layer<ShopifyBulk, never, never>;
|
|
24
|
+
layer: Layer.Layer<ShopifyAdmin, never, never>;
|
|
25
|
+
readOnlyBulkLayer: Layer.Layer<ReadOnlyShopifyBulk, never, never>;
|
|
26
|
+
readOnlyLayer: Layer.Layer<ReadOnlyShopifyAdmin, never, never>;
|
|
27
|
+
sent: SentOperation[];
|
|
28
|
+
};
|
|
29
|
+
//#endregion
|