The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Stripe from "@alchemy.run/stripe"; |
| 2 | import { expect } from "@alchemy.run/test"; |
| 3 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | import * as Redacted from "effect/Redacted"; |
| 6 | import { MinimumLogLevel } from "effect/References"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: Stripe.providers() }); |
| 9 | |
| 10 | const logLevel = Effect.provideService(MinimumLogLevel, process.env.DEBUG ? "Debug" : "Info"); |
| 11 | |
| 12 | test.provider( |
| 13 | "creates a logical restricted key with default props", |
| 14 | (stack) => |
| 15 | Effect.gen(function* () { |
| 16 | yield* stack.destroy(); |
| 17 | |
| 18 | const created = yield* stack.deploy( |
| 19 | Effect.gen(function* () { |
| 20 | const token = yield* Stripe.RestrictedApiKey("HostToken"); |
| 21 | yield* token.bind("RetrieveProduct", { |
| 22 | permissions: ["products_read"], |
| 23 | }); |
| 24 | return token; |
| 25 | }), |
| 26 | ); |
| 27 | |
| 28 | expect(created.id).toEqual(expect.any(String)); |
| 29 | expect(created.name).toEqual(expect.any(String)); |
| 30 | expect(Redacted.isRedacted(created.value)).toEqual(true); |
| 31 | expect(created.permissions).toEqual(["products_read"]); |
| 32 | |
| 33 | yield* stack.destroy(); |
| 34 | }).pipe(logLevel), |
| 35 | { |
| 36 | tags: ["provider:stripe", "provider:stripe:restrictedapikey", "live"], |
| 37 | timeout: 120_000, |
| 38 | }, |
| 39 | ); |
| 40 | |
| 41 | test.provider( |
| 42 | "creates a logical restricted key and merges bound permissions", |
| 43 | (stack) => |
| 44 | Effect.gen(function* () { |
| 45 | yield* stack.destroy(); |
| 46 | |
| 47 | const created = yield* stack.deploy( |
| 48 | Effect.gen(function* () { |
| 49 | const token = yield* Stripe.RestrictedApiKey("HostToken", { |
| 50 | permissions: ["customers_read"], |
| 51 | }); |
| 52 | yield* token.bind("RetrieveProduct", { |
| 53 | permissions: ["products_read"], |
| 54 | }); |
| 55 | return token; |
| 56 | }), |
| 57 | ); |
| 58 | |
| 59 | expect(created.id).toEqual(expect.any(String)); |
| 60 | expect(created.name).toEqual(expect.any(String)); |
| 61 | expect(Redacted.isRedacted(created.value)).toEqual(true); |
| 62 | expect(created.permissions).toEqual(["customers_read", "products_read"]); |
| 63 | |
| 64 | const updated = yield* stack.deploy( |
| 65 | Effect.gen(function* () { |
| 66 | const token = yield* Stripe.RestrictedApiKey("HostToken", { |
| 67 | permissions: ["customers_read", "customers_write"], |
| 68 | }); |
| 69 | yield* token.bind("RetrieveProduct", { |
| 70 | permissions: ["products_read"], |
| 71 | }); |
| 72 | return token; |
| 73 | }), |
| 74 | ); |
| 75 | |
| 76 | expect(updated.id).toEqual(created.id); |
| 77 | expect(updated.permissions).toEqual(["customers_read", "customers_write", "products_read"]); |
| 78 | |
| 79 | yield* stack.destroy(); |
| 80 | }).pipe(logLevel), |
| 81 | { |
| 82 | tags: ["provider:stripe", "provider:stripe:restrictedapikey", "live"], |
| 83 | timeout: 120_000, |
| 84 | }, |
| 85 | ); |