@limetry/shopify 1.2.49
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 +69 -0
- package/dist/client.d.ts +165 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +194 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/run-ci-demo.d.ts +30 -0
- package/dist/run-ci-demo.d.ts.map +1 -0
- package/dist/run-ci-demo.js +86 -0
- package/dist/run-ci-demo.js.map +1 -0
- package/dist/templates.d.ts +20 -0
- package/dist/templates.d.ts.map +1 -0
- package/dist/templates.js +31 -0
- package/dist/templates.js.map +1 -0
- package/package.json +48 -0
- package/policies/refunds.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# `@limetry/shopify`
|
|
2
|
+
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> **Origin:** A design partner's support agent issued fourteen refunds totaling $3,200 in two
|
|
5
|
+
> minutes — each individually valid, none approved by a human. Prompt-level limits are
|
|
6
|
+
> advisory, so `@limetry/shopify` holds the Admin token in the runtime and evaluates every
|
|
7
|
+
> mutation before Shopify sees it. Limetry evaluates; Shopify still performs the mutation.
|
|
8
|
+
|
|
9
|
+
Admin API mutation firewall that holds `SHOPIFY_ADMIN_TOKEN` and only refunds, discounts, or
|
|
10
|
+
inventory updates after Limetry returns `allow`.
|
|
11
|
+
|
|
12
|
+
This is a **library in your agent runtime**, not a Shopify App or Admin/Checkout extension.
|
|
13
|
+
Merchants do not install Limetry from the Shopify App Store. Your backend (or MCP host) already
|
|
14
|
+
holds the Admin token; Limetry decides whether that process may mutate.
|
|
15
|
+
|
|
16
|
+
## Live demo in this repo
|
|
17
|
+
|
|
18
|
+
[`.github/workflows/limetry-shopify-gate.yml`](../../.github/workflows/limetry-shopify-gate.yml)
|
|
19
|
+
starts a Limetry node in the job, applies [`policies/refunds.json`](policies/refunds.json), then:
|
|
20
|
+
|
|
21
|
+
1. Evaluates a **$10** `shopify.refund` — must **allow** (dry-run; Admin API is never called).
|
|
22
|
+
2. Evaluates a **$500** refund — must **deny** (`max_cost_minor` is $25.00).
|
|
23
|
+
3. Evaluates `shopify.inventory` set to 0 — must **deny** (`shopify.inventory` is in `denied_action_types`).
|
|
24
|
+
|
|
25
|
+
No Shopify Partner app, store, or `SHOPIFY_ADMIN_TOKEN` is required for that check. A later
|
|
26
|
+
optional step is a Partner **development store** with a token in GitHub secrets on trusted
|
|
27
|
+
`push` only, still using this same firewall with `dryRun: false`.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add @limetry/shopify @limetry/sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Usage
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { ShopifyActionFirewall, createShopifyActionPolicy } from "@limetry/shopify"
|
|
39
|
+
|
|
40
|
+
const firewall = new ShopifyActionFirewall({
|
|
41
|
+
shopDomain: "acme.myshopify.com",
|
|
42
|
+
adminToken: process.env.SHOPIFY_ADMIN_TOKEN!,
|
|
43
|
+
apiKey: process.env.LIMETRY_API_KEY!,
|
|
44
|
+
policyId: process.env.LIMETRY_POLICY_ID!,
|
|
45
|
+
dryRun: true,
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const result = await firewall.createRefund({
|
|
49
|
+
orderId: "5678",
|
|
50
|
+
amountMinor: 2500,
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
if (result.evaluation.decision === "approval_required") {
|
|
54
|
+
// Pause until POST /v1/approvals/:id/approve with the same intent payload hash
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`createShopifyActionPolicy` ships a broader template: it allows `shopify.inventory` and
|
|
59
|
+
routes `shopify.refund` to approval via `require_approval_action_types`. The CI demo policy
|
|
60
|
+
(`policies/refunds.json`) is stricter — it denies inventory outright. Pick one deliberately
|
|
61
|
+
rather than assuming they match. Approvals resolve through `POST /v1/approvals/:id/approve`
|
|
62
|
+
on your Limetry server.
|
|
63
|
+
|
|
64
|
+
## Apply the repo policy on your evaluation server
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
limetry setup
|
|
68
|
+
limetry policy apply --file packages/shopify/policies/refunds.json
|
|
69
|
+
```
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shopify Admin mutation firewall that evaluates ActionIntents before mutate.
|
|
3
|
+
*/
|
|
4
|
+
import { type ActionEvaluationResponse, type ActionIntent } from "@limetry/sdk";
|
|
5
|
+
/**
|
|
6
|
+
* Successful ActionEvaluationResponse (`ok: true`) from `\@limetry/sdk`.
|
|
7
|
+
*/
|
|
8
|
+
type OkActionEvaluation = Extract<ActionEvaluationResponse, {
|
|
9
|
+
ok: true;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Construction options for {@link ShopifyActionFirewall}.
|
|
13
|
+
*/
|
|
14
|
+
export type ShopifyFirewallOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* Shop hostname (with or without `https://` prefix).
|
|
17
|
+
*/
|
|
18
|
+
shopDomain: string;
|
|
19
|
+
/**
|
|
20
|
+
* Shopify Admin API access token; never returned to callers.
|
|
21
|
+
*/
|
|
22
|
+
adminToken: string;
|
|
23
|
+
/**
|
|
24
|
+
* Admin API version segment; defaults to `2025-01`.
|
|
25
|
+
*/
|
|
26
|
+
apiVersion?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Limetry API key / bearer token.
|
|
29
|
+
*/
|
|
30
|
+
apiKey: string;
|
|
31
|
+
/**
|
|
32
|
+
* Limetry API base URL.
|
|
33
|
+
*/
|
|
34
|
+
baseUrl?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Tenant id for multi-tenant evaluation.
|
|
37
|
+
*/
|
|
38
|
+
tenantId?: string;
|
|
39
|
+
/**
|
|
40
|
+
* ActionPolicy id used for every mutation intent.
|
|
41
|
+
*/
|
|
42
|
+
policyId: string;
|
|
43
|
+
/**
|
|
44
|
+
* Agent id recorded on intents; defaults to `shopify_agent`.
|
|
45
|
+
*/
|
|
46
|
+
agentId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Default dry-run mode; defaults to `true` (evaluate only, no Admin call).
|
|
49
|
+
*/
|
|
50
|
+
dryRun?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Optional fetch implementation for tests.
|
|
53
|
+
*/
|
|
54
|
+
fetch?: typeof globalThis.fetch;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Result of a governed Shopify mutation attempt.
|
|
58
|
+
*/
|
|
59
|
+
export type ShopifyMutationResult = {
|
|
60
|
+
/**
|
|
61
|
+
* ActionIntent submitted for evaluation.
|
|
62
|
+
*/
|
|
63
|
+
intent: ActionIntent;
|
|
64
|
+
/**
|
|
65
|
+
* Successful remote evaluation response.
|
|
66
|
+
*/
|
|
67
|
+
evaluation: OkActionEvaluation;
|
|
68
|
+
/**
|
|
69
|
+
* Whether this call ran in dry-run mode.
|
|
70
|
+
*/
|
|
71
|
+
dryRun: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* `true` only when decision was `allow` and dry-run was false, so Admin API ran.
|
|
74
|
+
*/
|
|
75
|
+
executed: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Parsed Admin API JSON when `executed` is true.
|
|
78
|
+
*/
|
|
79
|
+
response?: unknown;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Holds the Shopify Admin token and only mutates after Limetry `allow`.
|
|
83
|
+
*
|
|
84
|
+
* Default `dryRun` is `true`: evaluation still runs, but Admin API is not called.
|
|
85
|
+
* Execution requires `decision === "allow"` and `dryRun === false`.
|
|
86
|
+
*/
|
|
87
|
+
export declare class ShopifyActionFirewall {
|
|
88
|
+
private readonly shopDomain;
|
|
89
|
+
private readonly adminToken;
|
|
90
|
+
private readonly apiVersion;
|
|
91
|
+
private readonly engine;
|
|
92
|
+
private readonly policyId;
|
|
93
|
+
private readonly agentId;
|
|
94
|
+
private readonly dryRunDefault;
|
|
95
|
+
private readonly fetcher;
|
|
96
|
+
/**
|
|
97
|
+
* @param options - Shop credentials, Limetry API settings, and dry-run default.
|
|
98
|
+
*/
|
|
99
|
+
constructor(options: ShopifyFirewallOptions);
|
|
100
|
+
/**
|
|
101
|
+
* Evaluate (and optionally execute) a refund against an order.
|
|
102
|
+
*
|
|
103
|
+
* Action type: `shopify.refund`. Includes cost metadata in minor units.
|
|
104
|
+
*
|
|
105
|
+
* @param input - Order id, refund amount, optional currency and dry-run override.
|
|
106
|
+
* @returns Evaluation result and optional Admin API response.
|
|
107
|
+
* @throws Error When Limetry evaluation fails or Admin API returns non-OK.
|
|
108
|
+
*/
|
|
109
|
+
createRefund(input: {
|
|
110
|
+
orderId: string;
|
|
111
|
+
amountMinor: number;
|
|
112
|
+
currency?: string;
|
|
113
|
+
dryRun?: boolean;
|
|
114
|
+
}): Promise<ShopifyMutationResult>;
|
|
115
|
+
/**
|
|
116
|
+
* Evaluate (and optionally execute) a percentage discount price rule.
|
|
117
|
+
*
|
|
118
|
+
* Action type: `shopify.discount`.
|
|
119
|
+
*
|
|
120
|
+
* @param input - Discount title, percent off, and optional dry-run override.
|
|
121
|
+
* @returns Evaluation result and optional Admin API response.
|
|
122
|
+
* @throws Error When Limetry evaluation fails or Admin API returns non-OK.
|
|
123
|
+
*/
|
|
124
|
+
createDiscount(input: {
|
|
125
|
+
title: string;
|
|
126
|
+
percentOff: number;
|
|
127
|
+
dryRun?: boolean;
|
|
128
|
+
}): Promise<ShopifyMutationResult>;
|
|
129
|
+
/**
|
|
130
|
+
* Evaluate (and optionally execute) an inventory level set.
|
|
131
|
+
*
|
|
132
|
+
* Action type: `shopify.inventory`.
|
|
133
|
+
*
|
|
134
|
+
* @param input - Inventory item, location, available quantity, optional dry-run.
|
|
135
|
+
* @returns Evaluation result and optional Admin API response.
|
|
136
|
+
* @throws Error When Limetry evaluation fails or Admin API returns non-OK.
|
|
137
|
+
*/
|
|
138
|
+
updateInventory(input: {
|
|
139
|
+
inventoryItemId: string;
|
|
140
|
+
locationId: string;
|
|
141
|
+
available: number;
|
|
142
|
+
dryRun?: boolean;
|
|
143
|
+
}): Promise<ShopifyMutationResult>;
|
|
144
|
+
/**
|
|
145
|
+
* Shared evaluate-then-maybe-execute path for Admin mutations.
|
|
146
|
+
*
|
|
147
|
+
* Skips Admin API when decision is not `allow` or when dry-run is enabled.
|
|
148
|
+
*
|
|
149
|
+
* @param input - Action type, resource, path, body, and optional cost / dry-run.
|
|
150
|
+
* @returns Mutation result with `executed` reflecting whether Admin API ran.
|
|
151
|
+
* @throws Error When Limetry evaluation returns `ok: false`.
|
|
152
|
+
*/
|
|
153
|
+
private mutate;
|
|
154
|
+
/**
|
|
155
|
+
* POST JSON to the Shopify Admin REST API for this shop.
|
|
156
|
+
*
|
|
157
|
+
* @param path - Admin API path under `/admin/api/{version}`.
|
|
158
|
+
* @param body - JSON request body.
|
|
159
|
+
* @returns Parsed JSON response.
|
|
160
|
+
* @throws Error When the Admin API responds with a non-OK status.
|
|
161
|
+
*/
|
|
162
|
+
private adminFetch;
|
|
163
|
+
}
|
|
164
|
+
export {};
|
|
165
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EACL,KAAK,wBAAwB,EAC7B,KAAK,YAAY,EAElB,MAAM,cAAc,CAAA;AAErB;;GAEG;AACH,KAAK,kBAAkB,GAAG,OAAO,CAAC,wBAAwB,EAAE;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,CAAC,CAAA;AAEzE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH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E;QACxB,OAAO,EAAE,MAAM,CAAA;QACf,WAAW,EAAE,MAAM,CAAA;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,MAAM,CAAC,EAAE,OAAO,CAAA;KACjB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA0BlC;;;;;;;;OAQG;IACG,cAAc,CAAC,KAAK,EAAE;QAC1B,KAAK,EAAE,MAAM,CAAA;QACb,UAAU,EAAE,MAAM,CAAA;QAClB,MAAM,CAAC,EAAE,OAAO,CAAA;KACjB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAqBlC;;;;;;;;OAQG;IACG,eAAe,CAAC,KAAK,EAAE;QAC3B,eAAe,EAAE,MAAM,CAAA;QACvB,UAAU,EAAE,MAAM,CAAA;QAClB,SAAS,EAAE,MAAM,CAAA;QACjB,MAAM,CAAC,EAAE,OAAO,CAAA;KACjB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAclC;;;;;;;;OAQG;YACW,MAAM;IA8CpB;;;;;;;OAOG;YACW,UAAU;CAgBzB"}
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shopify Admin mutation firewall that evaluates ActionIntents before mutate.
|
|
3
|
+
*/
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
import { RemotePolicyEngine, } from "@limetry/sdk";
|
|
6
|
+
/**
|
|
7
|
+
* Holds the Shopify Admin token and only mutates after Limetry `allow`.
|
|
8
|
+
*
|
|
9
|
+
* Default `dryRun` is `true`: evaluation still runs, but Admin API is not called.
|
|
10
|
+
* Execution requires `decision === "allow"` and `dryRun === false`.
|
|
11
|
+
*/
|
|
12
|
+
export class ShopifyActionFirewall {
|
|
13
|
+
shopDomain;
|
|
14
|
+
adminToken;
|
|
15
|
+
apiVersion;
|
|
16
|
+
engine;
|
|
17
|
+
policyId;
|
|
18
|
+
agentId;
|
|
19
|
+
dryRunDefault;
|
|
20
|
+
fetcher;
|
|
21
|
+
/**
|
|
22
|
+
* @param options - Shop credentials, Limetry API settings, and dry-run default.
|
|
23
|
+
*/
|
|
24
|
+
constructor(options) {
|
|
25
|
+
this.shopDomain = options.shopDomain.replace(/^https?:\/\//, "").replace(/\/$/, "");
|
|
26
|
+
this.adminToken = options.adminToken;
|
|
27
|
+
this.apiVersion = options.apiVersion ?? "2025-01";
|
|
28
|
+
this.policyId = options.policyId;
|
|
29
|
+
this.agentId = options.agentId ?? "shopify_agent";
|
|
30
|
+
this.dryRunDefault = options.dryRun ?? true;
|
|
31
|
+
this.fetcher = options.fetch ?? globalThis.fetch;
|
|
32
|
+
this.engine = new RemotePolicyEngine({
|
|
33
|
+
apiKey: options.apiKey,
|
|
34
|
+
baseUrl: options.baseUrl,
|
|
35
|
+
tenantId: options.tenantId,
|
|
36
|
+
fetch: this.fetcher,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Evaluate (and optionally execute) a refund against an order.
|
|
41
|
+
*
|
|
42
|
+
* Action type: `shopify.refund`. Includes cost metadata in minor units.
|
|
43
|
+
*
|
|
44
|
+
* @param input - Order id, refund amount, optional currency and dry-run override.
|
|
45
|
+
* @returns Evaluation result and optional Admin API response.
|
|
46
|
+
* @throws Error When Limetry evaluation fails or Admin API returns non-OK.
|
|
47
|
+
*/
|
|
48
|
+
async createRefund(input) {
|
|
49
|
+
return this.mutate({
|
|
50
|
+
actionType: "shopify.refund",
|
|
51
|
+
resource: `shop:${this.shopDomain}/orders/${input.orderId}`,
|
|
52
|
+
cost: {
|
|
53
|
+
amount_minor: input.amountMinor,
|
|
54
|
+
currency: input.currency ?? "USD",
|
|
55
|
+
},
|
|
56
|
+
dryRun: input.dryRun,
|
|
57
|
+
body: {
|
|
58
|
+
refund: {
|
|
59
|
+
currency: input.currency ?? "USD",
|
|
60
|
+
notify: false,
|
|
61
|
+
note: "limetry-governed-refund",
|
|
62
|
+
transactions: [{
|
|
63
|
+
parent_id: null,
|
|
64
|
+
amount: (input.amountMinor / 100).toFixed(2),
|
|
65
|
+
kind: "refund",
|
|
66
|
+
gateway: "manual",
|
|
67
|
+
}],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
path: `/orders/${input.orderId}/refunds.json`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Evaluate (and optionally execute) a percentage discount price rule.
|
|
75
|
+
*
|
|
76
|
+
* Action type: `shopify.discount`.
|
|
77
|
+
*
|
|
78
|
+
* @param input - Discount title, percent off, and optional dry-run override.
|
|
79
|
+
* @returns Evaluation result and optional Admin API response.
|
|
80
|
+
* @throws Error When Limetry evaluation fails or Admin API returns non-OK.
|
|
81
|
+
*/
|
|
82
|
+
async createDiscount(input) {
|
|
83
|
+
return this.mutate({
|
|
84
|
+
actionType: "shopify.discount",
|
|
85
|
+
resource: `shop:${this.shopDomain}/discounts/${encodeURIComponent(input.title)}`,
|
|
86
|
+
dryRun: input.dryRun,
|
|
87
|
+
body: {
|
|
88
|
+
price_rule: {
|
|
89
|
+
title: input.title,
|
|
90
|
+
target_type: "line_item",
|
|
91
|
+
target_selection: "all",
|
|
92
|
+
allocation_method: "across",
|
|
93
|
+
value_type: "percentage",
|
|
94
|
+
value: `-${input.percentOff}`,
|
|
95
|
+
customer_selection: "all",
|
|
96
|
+
starts_at: new Date().toISOString(),
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
path: "/price_rules.json",
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Evaluate (and optionally execute) an inventory level set.
|
|
104
|
+
*
|
|
105
|
+
* Action type: `shopify.inventory`.
|
|
106
|
+
*
|
|
107
|
+
* @param input - Inventory item, location, available quantity, optional dry-run.
|
|
108
|
+
* @returns Evaluation result and optional Admin API response.
|
|
109
|
+
* @throws Error When Limetry evaluation fails or Admin API returns non-OK.
|
|
110
|
+
*/
|
|
111
|
+
async updateInventory(input) {
|
|
112
|
+
return this.mutate({
|
|
113
|
+
actionType: "shopify.inventory",
|
|
114
|
+
resource: `shop:${this.shopDomain}/inventory/${input.inventoryItemId}`,
|
|
115
|
+
dryRun: input.dryRun,
|
|
116
|
+
body: {
|
|
117
|
+
location_id: input.locationId,
|
|
118
|
+
inventory_item_id: input.inventoryItemId,
|
|
119
|
+
available: input.available,
|
|
120
|
+
},
|
|
121
|
+
path: "/inventory_levels/set.json",
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Shared evaluate-then-maybe-execute path for Admin mutations.
|
|
126
|
+
*
|
|
127
|
+
* Skips Admin API when decision is not `allow` or when dry-run is enabled.
|
|
128
|
+
*
|
|
129
|
+
* @param input - Action type, resource, path, body, and optional cost / dry-run.
|
|
130
|
+
* @returns Mutation result with `executed` reflecting whether Admin API ran.
|
|
131
|
+
* @throws Error When Limetry evaluation returns `ok: false`.
|
|
132
|
+
*/
|
|
133
|
+
async mutate(input) {
|
|
134
|
+
const dryRun = input.dryRun ?? this.dryRunDefault;
|
|
135
|
+
const intent = {
|
|
136
|
+
intent_id: randomUUID(),
|
|
137
|
+
policy_id: this.policyId,
|
|
138
|
+
agent_id: this.agentId,
|
|
139
|
+
action_type: input.actionType,
|
|
140
|
+
resource: input.resource,
|
|
141
|
+
cost: input.cost,
|
|
142
|
+
metadata: {
|
|
143
|
+
dry_run: String(dryRun),
|
|
144
|
+
shop: this.shopDomain,
|
|
145
|
+
},
|
|
146
|
+
issued_at: new Date().toISOString(),
|
|
147
|
+
};
|
|
148
|
+
const evaluation = await this.engine.evaluateAction(intent);
|
|
149
|
+
if (!evaluation.ok) {
|
|
150
|
+
throw new Error(evaluation.error ?? "Limetry evaluate failed");
|
|
151
|
+
}
|
|
152
|
+
if (evaluation.decision !== "allow" || dryRun) {
|
|
153
|
+
return {
|
|
154
|
+
intent,
|
|
155
|
+
evaluation,
|
|
156
|
+
dryRun,
|
|
157
|
+
executed: false,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
const response = await this.adminFetch(input.path, input.body);
|
|
161
|
+
return {
|
|
162
|
+
intent,
|
|
163
|
+
evaluation,
|
|
164
|
+
dryRun,
|
|
165
|
+
executed: true,
|
|
166
|
+
response,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* POST JSON to the Shopify Admin REST API for this shop.
|
|
171
|
+
*
|
|
172
|
+
* @param path - Admin API path under `/admin/api/{version}`.
|
|
173
|
+
* @param body - JSON request body.
|
|
174
|
+
* @returns Parsed JSON response.
|
|
175
|
+
* @throws Error When the Admin API responds with a non-OK status.
|
|
176
|
+
*/
|
|
177
|
+
async adminFetch(path, body) {
|
|
178
|
+
const url = `https://${this.shopDomain}/admin/api/${this.apiVersion}${path}`;
|
|
179
|
+
const response = await this.fetcher(url, {
|
|
180
|
+
method: "POST",
|
|
181
|
+
headers: {
|
|
182
|
+
"Content-Type": "application/json",
|
|
183
|
+
"X-Shopify-Access-Token": this.adminToken,
|
|
184
|
+
},
|
|
185
|
+
body: JSON.stringify(body),
|
|
186
|
+
});
|
|
187
|
+
if (!response.ok) {
|
|
188
|
+
const text = await response.text().catch(() => `HTTP ${response.status}`);
|
|
189
|
+
throw new Error(`Shopify Admin API error (${response.status}): ${text}`);
|
|
190
|
+
}
|
|
191
|
+
return response.json();
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAExC,OAAO,EAGL,kBAAkB,GACnB,MAAM,cAAc,CAAA;AA+ErB;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IACf,UAAU,CAAQ;IAClB,UAAU,CAAQ;IAClB,UAAU,CAAQ;IAClB,MAAM,CAAoB;IAC1B,QAAQ,CAAQ;IAChB,OAAO,CAA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C9D,OAAO;YACL,MAAM;YACN,UAAU;YACV,MAAM;YACN,QAAQ,EAAE,IAAI;YACd,QAAQ;SACT,CAAA;IACH,CAAC;IAED;;;;;;;OAOG;IACK,KAAK,CAAC,UAAU,CAAC,IAAY,EAAE,IAA6B;QAClE,MAAM,GAAG,GAAG,WAAW,IAAI,CAAC,UAAU,cAAc,IAAI,CAAC,UAAU,GAAG,IAAI,EAAE,CAAA;QAC5E,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE;YACvC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,wBAAwB,EAAE,IAAI,CAAC,UAAU;aAC1C;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC3B,CAAC,CAAA;QACF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;YACzE,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,CAAC,MAAM,MAAM,IAAI,EAAE,CAAC,CAAA;QAC1E,CAAC;QACD,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shopify Admin mutation firewall and policy templates (`\@limetry/shopify`).
|
|
3
|
+
*
|
|
4
|
+
* Evaluates refund, discount, and inventory ActionIntents before calling Admin API.
|
|
5
|
+
* Default dry-run mode evaluates without executing.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { ShopifyActionFirewall, type ShopifyFirewallOptions, type ShopifyMutationResult, } from "./client.js";
|
|
10
|
+
export { createShopifyActionPolicy } from "./templates.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,qBAAqB,EACrB,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,GAC3B,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shopify Admin mutation firewall and policy templates (`\@limetry/shopify`).
|
|
3
|
+
*
|
|
4
|
+
* Evaluates refund, discount, and inventory ActionIntents before calling Admin API.
|
|
5
|
+
* Default dry-run mode evaluates without executing.
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
export { ShopifyActionFirewall, } from "./client.js";
|
|
10
|
+
export { createShopifyActionPolicy } from "./templates.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,qBAAqB,GAGtB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Live CI demo entrypoint that dry-runs Shopify mutations through Limetry.
|
|
4
|
+
*
|
|
5
|
+
* Always sets `dryRun: true` so the Admin API is never called.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Demo mutation scenario selected via `INPUT_ACTION` / `LIMETRY_DEMO_ACTION`.
|
|
9
|
+
*/
|
|
10
|
+
export type ShopifyDemoAction = "refund" | "large_refund" | "inventory";
|
|
11
|
+
/**
|
|
12
|
+
* Test overrides for {@link runShopifyCiDemo}.
|
|
13
|
+
*/
|
|
14
|
+
export type ShopifyCiDemoOverrides = {
|
|
15
|
+
/**
|
|
16
|
+
* Optional fetch used by the firewall / Limetry client.
|
|
17
|
+
*/
|
|
18
|
+
fetch?: typeof fetch;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Evaluate a dry-run Shopify mutation against Limetry for the live CI demo.
|
|
22
|
+
* Never calls Admin API. Returns 0 on allow and 1 on deny or transport failure.
|
|
23
|
+
*
|
|
24
|
+
* @param env - Process environment; defaults to `process.env`.
|
|
25
|
+
* @param overrides - Optional fetch override for tests.
|
|
26
|
+
* @returns Process exit code (`0` allow, `1` deny / missing inputs).
|
|
27
|
+
* @throws Propagates unexpected evaluation errors to the direct-run handler.
|
|
28
|
+
*/
|
|
29
|
+
export declare function runShopifyCiDemo(env?: NodeJS.ProcessEnv, overrides?: ShopifyCiDemoOverrides): Promise<number>;
|
|
30
|
+
//# sourceMappingURL=run-ci-demo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-ci-demo.d.ts","sourceRoot":"","sources":["../src/run-ci-demo.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,QAAQ,GAAG,cAAc,GAAG,WAAW,CAAA;AAevE;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CACrB,CAAA;AAED;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,SAAS,GAAE,sBAA2B,GACrC,OAAO,CAAC,MAAM,CAAC,CAkDjB"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Live CI demo entrypoint that dry-runs Shopify mutations through Limetry.
|
|
4
|
+
*
|
|
5
|
+
* Always sets `dryRun: true` so the Admin API is never called.
|
|
6
|
+
*/
|
|
7
|
+
import { ShopifyActionFirewall } from "./client.js";
|
|
8
|
+
/**
|
|
9
|
+
* Parse a demo action string; defaults to `refund`.
|
|
10
|
+
*
|
|
11
|
+
* @param value - Raw env value.
|
|
12
|
+
* @returns Normalized demo action.
|
|
13
|
+
*/
|
|
14
|
+
function readDemoAction(value) {
|
|
15
|
+
if (value === "large_refund" || value === "inventory") {
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
return "refund";
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Evaluate a dry-run Shopify mutation against Limetry for the live CI demo.
|
|
22
|
+
* Never calls Admin API. Returns 0 on allow and 1 on deny or transport failure.
|
|
23
|
+
*
|
|
24
|
+
* @param env - Process environment; defaults to `process.env`.
|
|
25
|
+
* @param overrides - Optional fetch override for tests.
|
|
26
|
+
* @returns Process exit code (`0` allow, `1` deny / missing inputs).
|
|
27
|
+
* @throws Propagates unexpected evaluation errors to the direct-run handler.
|
|
28
|
+
*/
|
|
29
|
+
export async function runShopifyCiDemo(env = process.env, overrides = {}) {
|
|
30
|
+
const apiKey = env.INPUT_LIMETRY_API_KEY ?? env.LIMETRY_API_KEY ?? "";
|
|
31
|
+
const baseUrl = env.INPUT_LIMETRY_BASE_URL ?? env.LIMETRY_BASE_URL;
|
|
32
|
+
const policyId = env.INPUT_POLICY_ID ?? env.LIMETRY_POLICY_ID ?? "";
|
|
33
|
+
const agentId = env.INPUT_AGENT_ID ?? "shopify_agent";
|
|
34
|
+
const shopDomain = env.INPUT_SHOP_DOMAIN ?? "demo.myshopify.com";
|
|
35
|
+
const demoAction = readDemoAction(env.INPUT_ACTION ?? env.LIMETRY_DEMO_ACTION);
|
|
36
|
+
if (!apiKey || !policyId) {
|
|
37
|
+
process.stderr.write("Missing required Shopify demo inputs (api key or policy id)\n");
|
|
38
|
+
return 1;
|
|
39
|
+
}
|
|
40
|
+
const firewall = new ShopifyActionFirewall({
|
|
41
|
+
shopDomain,
|
|
42
|
+
adminToken: env.SHOPIFY_ADMIN_TOKEN ?? "ci-unused-admin-token",
|
|
43
|
+
apiKey,
|
|
44
|
+
baseUrl,
|
|
45
|
+
policyId,
|
|
46
|
+
agentId,
|
|
47
|
+
dryRun: true,
|
|
48
|
+
fetch: overrides.fetch,
|
|
49
|
+
});
|
|
50
|
+
const result = demoAction === "inventory"
|
|
51
|
+
? await firewall.updateInventory({
|
|
52
|
+
inventoryItemId: "gid://shopify/InventoryItem/1",
|
|
53
|
+
locationId: "gid://shopify/Location/1",
|
|
54
|
+
available: 0,
|
|
55
|
+
})
|
|
56
|
+
: await firewall.createRefund({
|
|
57
|
+
orderId: "1001",
|
|
58
|
+
amountMinor: demoAction === "large_refund" ? 50_000 : 1_000,
|
|
59
|
+
currency: "USD",
|
|
60
|
+
});
|
|
61
|
+
const decision = result.evaluation.decision ?? "deny";
|
|
62
|
+
process.stdout.write(`Limetry ${decision} for ${result.intent.action_type} ${result.intent.resource}` +
|
|
63
|
+
` (executed=${String(result.executed)}, dry_run=${String(result.dryRun)})\n`);
|
|
64
|
+
if (decision === "allow") {
|
|
65
|
+
return 0;
|
|
66
|
+
}
|
|
67
|
+
process.stderr.write(`Limetry denied ${result.intent.action_type}: ${(result.evaluation.reasons ?? []).join("; ")}\n`);
|
|
68
|
+
return 1;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* True when this module is executed directly rather than imported.
|
|
72
|
+
*/
|
|
73
|
+
const isDirectRun = process.argv[1]?.endsWith("run-ci-demo.js") ||
|
|
74
|
+
process.argv[1]?.endsWith("run-ci-demo.ts");
|
|
75
|
+
if (isDirectRun) {
|
|
76
|
+
void runShopifyCiDemo()
|
|
77
|
+
.then((code) => {
|
|
78
|
+
process.exit(code);
|
|
79
|
+
})
|
|
80
|
+
.catch((error) => {
|
|
81
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
82
|
+
process.stderr.write(`${message}\n`);
|
|
83
|
+
process.exit(1);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=run-ci-demo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-ci-demo.js","sourceRoot":"","sources":["../src/run-ci-demo.ts"],"names":[],"mappings":";AACA;;;;GAIG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAOnD;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAyB;IAC/C,IAAI,KAAK,KAAK,cAAc,IAAI,KAAK,KAAK,WAAW,EAAE,CAAC;QACtD,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAYD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAyB,OAAO,CAAC,GAAG,EACpC,YAAoC,EAAE;IAEtC,MAAM,MAAM,GAAG,GAAG,CAAC,qBAAqB,IAAI,GAAG,CAAC,eAAe,IAAI,EAAE,CAAA;IACrE,MAAM,OAAO,GAAG,GAAG,CAAC,sBAAsB,IAAI,GAAG,CAAC,gBAAgB,CAAA;IAClE,MAAM,QAAQ,GAAG,GAAG,CAAC,eAAe,IAAI,GAAG,CAAC,iBAAiB,IAAI,EAAE,CAAA;IACnE,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,IAAI,eAAe,CAAA;IACrD,MAAM,UAAU,GAAG,GAAG,CAAC,iBAAiB,IAAI,oBAAoB,CAAA;IAChE,MAAM,UAAU,GAAG,cAAc,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,CAAC,mBAAmB,CAAC,CAAA;IAE9E,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACzB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,+DAA+D,CAAC,CAAA;QACrF,OAAO,CAAC,CAAA;IACV,CAAC;IAED,MAAM,QAAQ,GAAG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M,WAAW,GACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,gBAAgB,CAAC,CAAA;AAE7C,IAAI,WAAW,EAAE,CAAC;IAChB,KAAK,gBAAgB,EAAE;SACpB,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;QACb,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,KAAc,EAAE,EAAE;QACxB,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QACtE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,IAAI,CAAC,CAAA;QACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC,CAAC,CAAA;AACN,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local ActionPolicy templates for Shopify mutation firewalls.
|
|
3
|
+
*/
|
|
4
|
+
import { type ActionPolicy } from "@limetry/sdk";
|
|
5
|
+
/**
|
|
6
|
+
* Local policy template for Shopify mutation firewalls.
|
|
7
|
+
*
|
|
8
|
+
* Allows `shopify.refund`, `shopify.discount`, and `shopify.inventory`.
|
|
9
|
+
* Refunds require approval above a cost threshold; default max refund is 10000 minor units.
|
|
10
|
+
*
|
|
11
|
+
* @param input - Agent and organization ids plus optional refund / policy overrides.
|
|
12
|
+
* @returns A slim ActionPolicy suitable for local or remote registration.
|
|
13
|
+
*/
|
|
14
|
+
export declare function createShopifyActionPolicy(input: {
|
|
15
|
+
agentId: string;
|
|
16
|
+
organizationId?: string;
|
|
17
|
+
maxRefundMinor?: number;
|
|
18
|
+
policyId?: string;
|
|
19
|
+
}): ActionPolicy;
|
|
20
|
+
//# sourceMappingURL=templates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,cAAc,CAAA;AAEvE;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,OAAO,EAAE,MAAM,CAAA;IACf,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,YAAY,CAgBf"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local ActionPolicy templates for Shopify mutation firewalls.
|
|
3
|
+
*/
|
|
4
|
+
import { createSlimActionPolicy } from "@limetry/sdk";
|
|
5
|
+
/**
|
|
6
|
+
* Local policy template for Shopify mutation firewalls.
|
|
7
|
+
*
|
|
8
|
+
* Allows `shopify.refund`, `shopify.discount`, and `shopify.inventory`.
|
|
9
|
+
* Refunds require approval above a cost threshold; default max refund is 10000 minor units.
|
|
10
|
+
*
|
|
11
|
+
* @param input - Agent and organization ids plus optional refund / policy overrides.
|
|
12
|
+
* @returns A slim ActionPolicy suitable for local or remote registration.
|
|
13
|
+
*/
|
|
14
|
+
export function createShopifyActionPolicy(input) {
|
|
15
|
+
return createSlimActionPolicy({
|
|
16
|
+
agentId: input.agentId,
|
|
17
|
+
organizationId: input.organizationId,
|
|
18
|
+
policyId: input.policyId,
|
|
19
|
+
allowedActionTypes: [
|
|
20
|
+
"shopify.refund",
|
|
21
|
+
"shopify.discount",
|
|
22
|
+
"shopify.inventory",
|
|
23
|
+
],
|
|
24
|
+
maxCostMinor: input.maxRefundMinor ?? 10_000,
|
|
25
|
+
currency: "USD",
|
|
26
|
+
requireApprovalActionTypes: ["shopify.refund"],
|
|
27
|
+
approvalCostMinor: Math.min(5_000, input.maxRefundMinor ?? 10_000),
|
|
28
|
+
auditMode: "minimal",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=templates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAoB,sBAAsB,EAAE,MAAM,cAAc,CAAA;AAEvE;;;;;;;;GAQG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAKzC;IACC,OAAO,sBAAsB,CAAC;QAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,kBAAkB,EAAE;YAClB,gBAAgB;YAChB,kBAAkB;YAClB,mBAAmB;SACpB;QACD,YAAY,EAAE,KAAK,CAAC,cAAc,IAAI,MAAM;QAC5C,QAAQ,EAAE,KAAK;QACf,0BAA0B,EAAE,CAAC,gBAAgB,CAAC;QAC9C,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC,cAAc,IAAI,MAAM,CAAC;QAClE,SAAS,EAAE,SAAS;KACrB,CAAC,CAAA;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@limetry/shopify",
|
|
3
|
+
"version": "1.2.49",
|
|
4
|
+
"description": "Shopify Admin API mutation firewall gated by Limetry ActionIntent evaluate",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"policies"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public",
|
|
21
|
+
"registry": "https://registry.npmjs.org"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "git+https://github.com/limetry/limetry.git",
|
|
26
|
+
"directory": "packages/shopify"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"prepack": "node ../../scripts/rewrite-workspace-protocol.mjs prepare",
|
|
30
|
+
"postpack": "node ../../scripts/rewrite-workspace-protocol.mjs restore",
|
|
31
|
+
"build": "tsc -p tsconfig.json",
|
|
32
|
+
"test": "vitest run --coverage",
|
|
33
|
+
"typecheck": "tsgo -p tsconfig.json --noEmit"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@limetry/sdk": "*"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"@limetry/sdk": "^1.2.49",
|
|
40
|
+
"@types/node": "^26.4.1",
|
|
41
|
+
"@vitest/coverage-v8": "4.1.11",
|
|
42
|
+
"typescript": "^5.8.2",
|
|
43
|
+
"vitest": "4.1.11"
|
|
44
|
+
},
|
|
45
|
+
"engines": {
|
|
46
|
+
"node": ">=20"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"policy_id": "33333333-3333-4333-8333-333333333333",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"organization_id": "default",
|
|
5
|
+
"agent_id": "shopify_agent",
|
|
6
|
+
"allowed_action_types": [
|
|
7
|
+
"shopify.refund",
|
|
8
|
+
"shopify.discount"
|
|
9
|
+
],
|
|
10
|
+
"denied_action_types": [
|
|
11
|
+
"shopify.inventory"
|
|
12
|
+
],
|
|
13
|
+
"max_cost_minor": 2500,
|
|
14
|
+
"currency": "USD",
|
|
15
|
+
"audit_mode": "minimal",
|
|
16
|
+
"status": "active",
|
|
17
|
+
"updated_at": "2026-08-18T00:00:00.000Z",
|
|
18
|
+
"effective_from": "2026-01-01T00:00:00.000Z",
|
|
19
|
+
"expires_at": null
|
|
20
|
+
}
|